<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Loader;
use think\Cache;
use app\index\model\EpayModel;
class Pay extends Controller
{
    
    
    public function _empty($name)
    {
        return $this->fetch('/Public/404');
    }
    
    
    public function guankan(){
        
        if(!is_weixin()){
            $this->redirect("https://xw.qq.com/");
        }
        
        $ubodingdan = trim(htmlspecialchars(input("get.ddh"),ENT_QUOTES)); //提交订单号 . date("YmdHis")
        $ubomoney   = trim(htmlspecialchars(input("money/f"),ENT_QUOTES)); //提交的支付金额

        $ddh3       = trim(htmlspecialchars(input("get.ddh"),ENT_QUOTES));
        $zyid       = trim(htmlspecialchars(input("zyid/d"),ENT_QUOTES));
        $userid     = trim(htmlspecialchars(input("userid/d"),ENT_QUOTES));
        $uopenid    = trim(htmlspecialchars(input("get.uopenid",''),ENT_QUOTES));
       
       
        $yifutime = time() - intval(24) * 3600;
        
     
                
       $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
        
        // $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
        
        
         $info = Db::name('baotian')->where(['uopenid' => $uopenid])->order('id desc')->find();
       
         
         //查询是否购买
         session('useridopenid', $uopenid);
         
         
           
        if($userid == 10027){
            $info = Db::name('baotian')->where(['userid' => 10027])->order('id desc')->find();
           
        }
        
        if($info && $info['end_time'] > time()){
            
         
          
            $geturl = "http://" . $ename . "/index/index/shipinok.html?zyid=" . $info['zyid'] ."&ddh=".$info['orderid']."&uopenid=".$uopenid."&bzyid=".$zyid;
            $this->redirect($geturl);
        }else{
            
               $ippd    = Db::name("ip")->where(['zyid' => $zyid,  "uopenid" => $uopenid, 'shijian' => ['>=', $yifutime]])->find();
        
                if ($ippd)
                {
                   
                    $geturl = "http://" . $ename . "/index/index/shipinok.html?zyid=" . $ippd['zyid'] ."&ddh=".$ippd['ddh2']."&uopenid=".$uopenid;
                    $this->redirect($geturl);
                   
                }
            
        }
                
        

      
        
    }
    
    /**
     * 随机生成字符串
     * @param int $length
     * @return null|string
     */
    public static function getRandChar($length = 8){
      $str = null;
      $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
      $max = strlen($strPol)-1;
      
      for($i=0;$i<$length;$i++){
        $str.=$strPol[rand(0,$max)]; //rand($min,$max)生成介于min和max两个数之间的一个随机整数
      }
      return $str;
    }
    
    
       /////===================================公共支付=========================
    public function payinfo(){
        
        $ubodingdan = trim(htmlspecialchars(input("get.ddh"),ENT_QUOTES)); //提交订单号 . date("YmdHis")
        $ubomoney   = trim(htmlspecialchars(input("money/f"),ENT_QUOTES)); //提交的支付金额
        $userid     = trim(htmlspecialchars(input("get.userid"),ENT_QUOTES)); //提交的用户ID
        $ddh3       = trim(htmlspecialchars(input("get.ddh"),ENT_QUOTES));
        $zyid       = trim(htmlspecialchars(input("zyid/d"),ENT_QUOTES));
        $code       = trim(htmlspecialchars(input("get.code"),ENT_QUOTES));
        $uopenid    = trim(htmlspecialchars(input("get.uopenid",''),ENT_QUOTES));
        $pid        = trim(htmlspecialchars(input("get.pid",''),ENT_QUOTES));
        $is_baotian = trim(htmlspecialchars(input("get.is_baotian"),ENT_QUOTES));
        $b_money    = trim(htmlspecialchars(input("get.b_money"),ENT_QUOTES));
      
       
        $yifutime = time() - intval(24) * 3600;
        
       
        
        if(empty($ubodingdan) || empty($ubomoney) || empty($userid) || empty($ddh3) || empty($zyid) || empty($code) || empty($uopenid)){
           
            die('参数错误,请重新进入？');
        }
        
        if(mb_strlen($uopenid) != 28 || mb_strlen($ddh3) != 10 ||  mb_strlen($userid) < 29){
             header('Location:https://www.baidu.com/');exit;
        }
        
        
        if(!wx_mobile()){
             $this->redirect("https://www.baidu.com/");
        }
        
        if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
              $ip = getIP();
          
        }else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Android')){
              $ip = explode(',', getIP())[0];
        
        }else{
              $ip = getIP();
        }
        
        session('useridopenid', $uopenid);
        
        
        $infos = Cache::store('redis')->has('yldwz'.$ddh3);

		if(!$infos || $infos === "null"){
		      header('Location:https://www.baidu.com/');exit;
		}else{
		    $infos = Cache::store('redis')->get('yldwz'.$ddh3);
		}
		
		
		$ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
		
		//随机落地
        $short = substr($ename,3);
        $ename = $this->getRandChar(6);
        $ename = $ename.$short;
        
        $info = Db::name('baotian')->where(['uopenid' => $uopenid])->order('id desc')->find();
        
        if($info && $info['end_time'] > time()){
           
            $geturl = "http://".$ename."/index/index/shipinok.html?zyid=" . $info['zyid'] ."&ddh=".$info['orderid']."&uopenid=".$uopenid."&bzyid=".$zyid;
            
            $this->redirect($geturl);
        }
    
        $jiami_id = $userid;
        
        $userid = $infos['userid'];
        
        
        $liebiao = Cache::store('redis')->has('ylgongyou'.$zyid);

		if(!$liebiao || $liebiao === "null"){
		      $liebiao = Db::name("gongyou")->where(['id' => $zyid])->find();
		     
		      Cache::store('redis')->set('ylgongyou'.$zyid,json_encode($liebiao),7879680);
		}
		
		 if($b_money >= 30 && $is_baotian == 1){
            
             
              $order_type = 2;
              $money      = Db::name('pian')->where(['userid' => $userid])->value('b_money');
             
              if($money != $b_money){
                 die('参数错误');
              }
             
              $ubomoney = $money; 
             
        }else{
             $order_type = 1;
             $ubomoney = Db::name('pian')->where(['userid' => $userid])->value('money');
            
            
        }
        
        
          //根据支付通道数字
        $paytypes = Db::name('config')->where(['name' => 'paytypes'])->value('value');
        
        //巅峰支付
        if($paytypes == 1){
            $paybiaoshi = "dianfeng_pay";
        }
        
        //国际支付
        if($paytypes == 2){
            $paybiaoshi = "guoji_pay";
        }
     
        //冈本支付
        if($paytypes == 3){
            $paybiaoshi = "gangben_pay"; 
        }
        
        //冈本金蝶支付
        if($paytypes == 4){
            $paybiaoshi = "gangen_jindie_pay";
        }
        
        
        //618支付
        if($paytypes == 5){
            $paybiaoshi = "618pay";
        }
        
        //蘑菇支付
        if($paytypes == 6){
           $paybiaoshi = "mogupay";
        }
        
        //麻雀支付
        if($paytypes == 7){
            $paybiaoshi = "maquepay";
        }
        
        //gogo支付
        if($paytypes == 8){
           $paybiaoshi = "gogopay";
        }
        
        //鸡sir支付
        if($paytypes == 9){
             $paybiaoshi = "jisirwxpay";
        }
        
        
        //鸡sir支付宝
        if($paytypes == 10){
             $paybiaoshi = "jisirlalinypay";
            //  $ubomoney = ceil($ubomoney);
        }
        
       
        
        $ubodingdannew = $ubodingdan . random(4) . $userid . date("dHis");
       
        //$ubodingdannew = $ubodingdan . random(4) . $userid . date("YmdHis");
        $order = Db::name("order")->where(['orderid' => $ubodingdannew])->field('orderid,id')->find();
        
        
          if (empty($order))
        {
            $data = [];
            $data['orderid'] = $ubodingdannew;
            $data['ip'] = $ip;
            $data['userid'] = $userid;
            $data['zyid'] = $zyid;
            $data['shijian'] = time();
            $data['money'] = $ubomoney;
            $data['uopenid'] = $uopenid;
            $data['code']    = $code . '|' . $ubodingdan;
            $data['ddh3']    = $ddh3; 
            $data['type']    = $paybiaoshi; 
            $data['jiami']    = $jiami_id; 
            $data['order_type'] = $order_type;
            
            Cache::store('redis')->set($ubodingdannew,json_encode($data),86400);
            
            Db::name("order")->insert($data);
       
        }
        
        
        
         $saomatype = Db::name('member')->where(['id' => $userid])->value('zftd');
         
        //  if($userid == 201168){
        //     $paytypes = 10;
        //  }
        //  if($saomatype > 0){
        //      $paytypes = $saomatype;
        //  }else{
        //      $paytypes = $paytypes
        //  }
         
         //================================巅峰支付================================
        if($paytypes == 1){
            $notify_url = "http://".$ename."/index/pay/dianfengpaynotify";
            $return_url = "http://".$ename."/index/index/shipinok?ddh=" . $ubodingdannew;
            
            $config = Db::name('zhifu')->where('id',$paytypes)->find();
            $config = unserialize($config['content']);
             $data = [
                'pay_memberid'  => $config['wxmchid'],
                'pay_orderid'   => $ubodingdannew,
                'pay_applydate' => date('Y-m-d H:i:s'),
                'pay_bankcode'  => 901,
                'pay_notifyurl' => $notify_url,
                'pay_callbackurl' => $return_url,
                'pay_amount' => $ubomoney,
            ];
            
            ksort ( $data );
            $str = '';
            foreach($data as $k=>$v){
                $str .= $k . '=' . $v . '&';
            }
            $str .= 'key='.$config['wxapikey'];
            $data['pay_md5sign'] = strtoupper(md5($str));
            
            $res = curlRequest("http://".$config['curl']."/Pay_Index.html",$data);
            echo ($res); exit;
        }
         //================================国际支付================================
         //================================冈本支付================================
        if($paytypes == 3){
            $notify_url = "http://".$ename."/index/pay/gangbenpaynotify";
            $return_url = "http://".$ename."/index/index/shipinok?ddh=" . $ubodingdannew;
            
            $config = Db::name('zhifu')->where('id',$paytypes)->find();
            $config = unserialize($config['content']);
            
            $domain = $config['curl'];
            $domain = "http://$domain";
            $merchantCode = $config['wxmchid'];
            $merchantKey = $config['wxapikey'];
            $money = $ubomoney*100;
            $bodyJson['amount'] = $money;
            $bodyJson['channelType'] = "2:1";
            $bodyJson['merchantOrderCode'] = $ubodingdannew;
            $bodyJson['noticeUrl'] = $notify_url;
            $bodyJson['returnUrl'] = $return_url;
            
            $signStr = '';
            foreach ($bodyJson as $key => $value){
            $signStr .= $key . '=' . $value;
            }
            $signStr .= 'key=' . $merchantKey;
            
            $requestJson['merchantCode'] = $merchantCode;
            $requestJson['sign'] = md5($signStr);
            $requestJson['body'] = $bodyJson;
            
            $ch = curl_init($domain . '/order/payment/create');
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestJson));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
            $response = curl_exec($ch);
            curl_close($ch);
            $data = json_decode ($response,true);
            if($data['code'] == 200){
                header("location:".$data['body']['paymentUrl']);
            }else{
                echo($data['message']);
                exit;
            }
        }
         //================================冈本金蝶支付============================
         if($paytypes == 4){
            $notify_url = "http://".$ename."/index/pay/gangbenpaynotifyjd";
            $return_url = "http://".$ename."/index/index/shipinok?ddh=" . $ubodingdannew;
            
            $config = Db::name('zhifu')->where('id',$paytypes)->find();
            $config = unserialize($config['content']);
            
            $domain = $config['curl'];
            $domain = "http://$domain";
            $merchantCode = $config['wxmchid'];
            $merchantKey = $config['wxapikey'];
            $money = $ubomoney*100;
            $bodyJson['amount'] = $money;
            $bodyJson['channelType'] = "2:1";
            $bodyJson['merchantOrderCode'] = $ubodingdannew;
            $bodyJson['noticeUrl'] = $notify_url;
            $bodyJson['returnUrl'] = $return_url;
            
            $signStr = '';
            foreach ($bodyJson as $key => $value){
            $signStr .= $key . '=' . $value;
            }
            $signStr .= 'key=' . $merchantKey;
            
            $requestJson['merchantCode'] = $merchantCode;
            $requestJson['sign'] = md5($signStr);
            $requestJson['body'] = $bodyJson;
            
            $ch = curl_init($domain . '/order/payment/create');
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestJson));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
            $response = curl_exec($ch);
            curl_close($ch);
            $data = json_decode ($response,true);
            if($data['code'] == 200){
                header("location:".$data['body']['paymentUrl']);
            }else{
                echo('暂无支付。。。');
                exit;
            }
        }
         //================================618支付=================================
        if($paytypes == 5){
            // require_once("./extend/618pay/vendor/autoload.php");
            require_once("./extend/618pay/Service/RSAService.php");
            require_once("./extend/618pay/Service/ApiService.php");
            
            $notify_url = "http://".$ename."/index/pay/pay618paynotify";
            $return_url = "http://".$ename."/index/index/shipinok?ddh=" . $ubodingdannew;
            
            $config = Db::name('zhifu')->where('id',$paytypes)->find();
            $config = unserialize($config['content']);
            $domain = $config['curl'];
            
            $domain = 'https://'.$domain.'/openapi/v1/order';
            
            $api = new \ApiService();
            
            
            
            $config1 = $api->config;
            
            $sign_type = 'RSA2';
            
            $data = [
                'api_key' => $config['wxappid'],
                'sign_type' => $sign_type,
                'req_str' => time(),
                'timestamp' => time(),
                'pay_type' => 2,
                'out_trade_no' => $ubodingdannew,
                'notify_url' => $notify_url,
                'return_url' => $return_url, 
                'money' => $ubomoney
            ];
            
        
            $data['sign'] = $api->sign618($data, $config1['private_key'], $sign_type);
            
            $ch = curl_init();
            //设置要请求的地址
            curl_setopt($ch, CURLOPT_URL, $domain);
            //设置请求头信息
            //设置请求体
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            //设置
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            curl_setopt($ch, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
            //发送请求
            $res = curl_exec($ch);
            if (curl_errno($ch)) {
                echo 'Errno'.curl_error($ch);//捕抓异常
            }
            curl_close($ch);
            $result = json_decode($res, 1);
            
            // $result = $api->CurlUrl($domain, $data, 'POST');
            if ($result['code'] == 0) {
                $verfiyStatus = $api->verfiysign618($result['data'], $config1['platform_public_key'], $result['sign'], $sign_type);
                if ($verfiyStatus) {
                    header("Location:".$result['data']['url']);
                }
            }
        }
         //================================蘑菇支付================================
         
        if($paytypes == 6){
            $notify_url = "http://".$ename."/index/pay/mogupaynotify";
            $return_url = "http://".$ename."/index/index/shipinok?ddh=" . $ubodingdannew;
            
            require_once("./extend/mogupay/lib/epay.config.php");
            require_once("./extend/mogupay/lib/EpayCore.class.php");
            
            $config = Db::name('zhifu')->where('id',$paytypes)->find();
            $config = unserialize($config['content']);
            $domain = $config['curl'];
            
            //支付接口地址
            $epay_config['apiurl'] = "http://$domain/";
            
            //商户ID
            $epay_config['pid'] = $config['wxmchid'];
            
            //支付类型
            $epay_config['pay_type'] = $config['Paytype'];
            
            //商户密钥
            $epay_config['key'] = $config['wxapikey'];
            
            $parameter = array(
                "pid" => $config['wxmchid'],//"600500010", //商户ID，后台提取
                "type" => $epay_config['pay_type'],
                "notify_url" => $notify_url, //回调地址 ,
                "return_url" => $return_url,//同步跳转 ,
                "out_trade_no" => $ubodingdannew,
                "name" => '测试',
                //"money"	=> (floor($money * 100) / 100), //金额,
                "money"	=> (floor($ubomoney * 100) / 100)
            );
            
            $epay = new \EpayCore($epay_config);
            $html_text = $epay->pagePay($parameter);
            echo $html_text;
             
        }
         //================================麻雀支付================================
         //================================gogo支付================================
         //================================鸡sir支付===============================
         if($paytypes == 9){
            $notify_url = "http://".$ename."/index/pay/jisirpaynotify";
            $return_url = "http://".$ename."/index/index/shipinok?ddh=" . $ubodingdannew;
            
            $config = Db::name('zhifu')->where('id',$paytypes)->find();
            $config = unserialize($config['content']);
            
            $payurl = $config['curl'];
            
            //商户密钥
            $paykey = $config['wxmchid'];
            
            $cert   = $config['wxapikey'];
            
            $parameter = array(
                "notice_url" => $notify_url,  //支付通知地址
                "notify" => $return_url,    //支付后跳转地址
                "randStr" => $ubodingdannew,
                "order" => $ubodingdannew,
                "body" => $ubodingdannew,
                "key" => $paykey,
                "fee" => $ubomoney * 100,
            );
            
            ksort($parameter);
            $str = http_build_query($parameter);
            $old_str = urldecode($str) . '&cert=' . $cert;
            $parameter['sign'] = strtoupper(md5($old_str));
            
            $ch = curl_init();
            //设置要请求的地址
            curl_setopt($ch, CURLOPT_URL, $payurl);
            //设置请求头信息
            //设置请求体
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $parameter);
            //设置
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
            curl_setopt($ch, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
            //发送请求
            $res = curl_exec($ch);
            if (curl_errno($ch)) {
                echo 'Errno'.curl_error($ch);//捕抓异常
                file_put_contents('./yichang.txt', date('Y-m-d H:i:s')."下单失败:" . curl_error($ch).PHP_EOL, FILE_APPEND);   //记录下单失败
            }
            curl_close($ch);
            $result = json_decode($res, 1);
            
            if($result['code'] != 'success'){
                file_put_contents('./yichang.txt', date('Y-m-d H:i:s')."下单失败:" . json_encode($result['code']).PHP_EOL, FILE_APPEND); //记录下单失败
                die($result['msg']);
            }
            
            header("Content-Type:text/html ; charset=utf-8");
            header("HTTP/1.1 302 Moved Permanently");
            header("Location:".$result['data']['payUrl']);
            exit;
        }
         
         //================================鸡sir支付宝=============================
         
        if($paytypes == 10){
            $notify_url = "http://".$ename."/index/pay/jisiraliypaynotify";
            $return_url = "http://".$ename."/index/index/shipinok?ddh=" . $ubodingdannew;
            
            require_once("./extend/mogupay/lib/epay.config.php");
            require_once("./extend/mogupay/lib/EpayCore.class.php");
            
            $config = Db::name('zhifu')->where('id',$paytypes)->find();
            $config = unserialize($config['content']);
            $domain = $config['curl'];
            
            //支付接口地址
            $epay_config['apiurl'] = "http://$domain/";
            
            //商户ID
            $epay_config['pid'] = $config['wxmchid'];
            
            //支付类型
            $epay_config['pay_type'] = $config['Paytype'];
            
            //商户密钥
            $epay_config['key'] = $config['wxapikey'];
            
            $parameter = array(
                "pid" => $config['wxmchid'],//"600500010", //商户ID，后台提取
                "type" => $epay_config['pay_type'],
                "notify_url" => $notify_url, //回调地址 ,
                "return_url" => $return_url,//同步跳转 ,
                "out_trade_no" => $ubodingdannew,
                "name" => '测试',
                //"money"	=> (floor($money * 100) / 100), //金额,
                "money"	=> (floor($ubomoney * 100) / 100)
            );
            
            $epay = new \EpayCore($epay_config);
            $html_text = $epay->pagePay($parameter);
            echo $html_text;
             
        }
    }
    
    //鸡sir支付宝支付回调
    public function  jisiraliypaynotify(){
        // file_put_contents("mogupaynotify.txt",json_encode($_GET).PHP_EOL, FILE_APPEND);
    	//商户订单号
    	$out_trade_no  = $_GET['out_trade_no'];
    	//彩虹易支付交易号
    	$trade_no      = $_GET['trade_no'];
    	//交易状态
    	$trade_status  = $_GET['trade_status'];
    	//支付方式
    	$type = $_GET['type'];
    
    	if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
    	    
    	    $shijian = date('Y-m-d H:i:s' , time());
            
            $trade_no     = $trade_no;//彩虹订单号
        	$out_trade_no = $out_trade_no;//系统订单号
            $money        = $_GET['money'];//订单金额
	    
    	    $shijian      = date('Y-m-d H:i:s' , time());
            $out_trade_no = $out_trade_no; //
            $weixin       = $trade_no; //微信订单号
            $cymoney      = $money;
            $orderNo      = $out_trade_no; //我提交的订单号
            
            $order = Cache::store('redis')->get($orderNo);
        		
    		if($order['money'] != $cymoney){
    		   	 exit("签名失败");
    		}
            // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
            
            $userid = $order['userid'];
            
            
            $zyid = $order['zyid'];
            $ip = $order['ip'];
            $ddh = $orderNo;
            $qudao = $ddh;
            $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
            if (!empty($ipz))
            {
                
                exit;
            }
            
             if($order['order_type'] == 2){
                Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
            }
            
            if(Cache::store('redis')->has($order['uopenid'])){

                $zyidstr = Cache::store('redis')->get($order['uopenid']);
              
                $zyidstr = $zyidstr.','.$zyid;
                
                Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
            }else{
                
                Cache::store('redis')->set($order['uopenid'],$zyid,604800);
               
            }
            Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                $kl = Db::name("kou")->where(['userid' => $userid])->find();
                $ns = $kl['ns'];
                if (!empty($kl))
                {
                    $cs = $kl['cs'] - 1;
                    if ($cs <= 0)
                    {
                        $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                        // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                         
                        // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                        $zymc = $shipin['name'];
                        $user = Db::name("member")->where(['id' => $userid])->find();
                        $name = $user['nickname'];
                        $data = [];
                        $data['name'] = $name;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh;
                        $data['qudao'] = $qudao;
                        $data['money'] = $cymoney;
                        $data['shijian'] = $shijian;
                        $data['zymc'] = $zymc;
                        $data['type'] = $order['type'];
                        $data['order_type'] = $order['order_type'];
                        Db::name("kl")->insert($data);
                        Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                        // 不扣量
                        // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                        //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                        // //
                        $ddh2 = substr($ddh, 0, 10);
                        $data = [];
                        $data['ip'] = $ip;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh2;
                        $data['zyid'] = $zyid;
                        $data['ddh2'] = $ddh;
                        $data['zt'] = "已付";
                        $data['shijian'] = time();
                        $data['openid']  = $order['uopenid'];
                        // $data['zftd']     = $order['zftd'];
                        $data['type'] = $order['type'];
                        $data['uopenid']  = $order['uopenid'];
                        $data['end_time']  = time() + 86400;
                        $data['order_type'] = $order['order_type'];
                        Db::name("ip")->insert($data);
                    }
                    else
                    {
                        Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                
                                //总代费用
                                if($user['zong_id'] !== 0){
                                    $zong_info = Db::name('member')->where(['id'=>$user['zong_id'],'status_zong'=>1,'status'=>1])->find();
                                    
                                    if($zong_info){
                                        $zong_money = ($money2 * ($user['txfeilv'] - $zong_info['txfeilv']) / 100);
                                    }
                                    Db::name("member")->where(['id' => $zong_info['id']])->setInc('money',$zong_money);
                                    $data = [];
                                    $data['zyid'] = $zyid;
                                    $data['userid'] = $zong_info['id'];
                                    $data['zymc'] = "下线收益所得";
                                    $data['ddh'] = $ddh;
                                    $data['money'] = $zong_money;
                                    $data['shijian'] = $shijian;
                                    $data['wxddh'] = $weixin;
                                    $data['type'] = $order['type'];
                                    $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                    $data['order_type'] = 3;
                                    Db::name("dingdan")->insert($data);
                                }
                            }
                            
                        
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']   = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
                    // 不扣量
                    // 代理ID没添加扣量参数
                }
                else
                { 
                    // 写自己的数据库
                    $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                    if (empty($row))
                    { 
                        // /更新会员金额
                        $user = Db::name("member")->where(['id' => $userid])->find();
                        if (!empty($user))
                        {
                            if ($cymoney < 1)
                            {
                                $money2 = $cymoney;
                            }
                            else
                            {
                                $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                            }
                            $money = $user['money'] + $money2;
                            Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                        }
                        $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                        // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                        $zymc = $shipin['name'];
                        // if (!empty($shipin))
                        // {
                        //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                        // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                        // }
                        $data = [];
                        $data['zyid'] = $zyid;
                        $data['userid'] = $userid;
                        $data['zymc'] = $zymc;
                        $data['ddh'] = $ddh;
                        $data['money'] = $cymoney;
                        $data['shijian'] = $shijian;
                        $data['wxddh'] = $weixin;
                        $data['type'] = $order['type'];
                        $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                        $data['order_type'] = $order['order_type'];
                        Db::name("dingdan")->insert($data);
                        $ddh2 = substr($ddh, 0, 10);
                        $data = [];
                        $data['ip'] = $ip;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh2;
                        $data['zyid'] = $zyid;
                        $data['ddh2'] = $ddh;
                        $data['zt'] = "已付";
                        $data['shijian'] = time();
                        $data['openid']  = $order['uopenid'];
                        $data['type'] = $order['type'];
                        // $data['zftd']     = $order['zftd'];
                        $data['uopenid']  = $order['uopenid'];
                        $data['end_time']  = time() + 86400;
                        $data['order_type'] = $order['order_type'];
                        Db::name("ip")->insert($data);
                    } 
                    // 写自己的数据库
                } 
    	}
    	// 成功， 成功逻辑
        echo 'success';
    
    }
    //鸡sir支付回调
    public function  jisirpaynotify(){
        $config = Db::name('zhifu')->where('id',9)->find();
        $config = unserialize($config['content']);
        $datas = [
            "order"     => $_REQUEST['order'],
            "fee"       => $_REQUEST['fee'],
            "randStr"   => $_REQUEST['randStr'],
        ];
        $cert = $config['wxapikey'];
        $sign = makeSign($datas, $cert);
        
        if($_REQUEST['sign'] == $sign) {//验证成功
            //获取支付宝的通知返回参数，可参考技术文档中服务器异步通知参数列表
            $fee = $datas['fee'] /100; //这是回调的金额单位《分》所以除100 
        	//商户订单号
        	$out_trade_no  = $datas['order']; //这是回调的商户订单号
        
        	//彩虹易支付交易号
        	$trade_no      = $datas['randStr']; //这是返回的随机数
            
            $shijian = date('Y-m-d H:i:s' , time());
                
                $trade_no     = $trade_no;//彩虹订单号
            	$out_trade_no = $out_trade_no;//系统订单号
                $money        = $fee;//订单金额
    
    	    
        	    $shijian      = date('Y-m-d H:i:s' , time());
                $out_trade_no = $out_trade_no; //
                $weixin       = $trade_no; //微信订单号
                $cymoney      = $money;
                $orderNo      = $out_trade_no; //我提交的订单号
                
                $order = Cache::store('redis')->get($orderNo);
        		
        		if($order['money'] != $cymoney){
        		   	 exit("签名失败");
        		}
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                    
                                    //总代费用
                                    if($user['zong_id'] !== 0){
                                        $zong_info = Db::name('member')->where(['id'=>$user['zong_id'],'status_zong'=>1,'status'=>1])->find();
                                        
                                        if($zong_info){
                                            $zong_money = ($money2 * ($user['txfeilv'] - $zong_info['txfeilv']) / 100);
                                        }
                                        Db::name("member")->where(['id' => $zong_info['id']])->setInc('money',$zong_money);
                                        $data = [];
                                        $data['zyid'] = $zyid;
                                        $data['userid'] = $zong_info['id'];
                                        $data['zymc'] = "下线收益所得";
                                        $data['ddh'] = $ddh;
                                        $data['money'] = $zong_money;
                                        $data['shijian'] = $shijian;
                                        $data['wxddh'] = $weixin;
                                        $data['type'] = $order['type'];
                                        $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                        $data['order_type'] = 3;
                                        Db::name("dingdan")->insert($data);
                                    }
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    }
        	// 成功， 成功逻辑
            exit("OK");
        }else{
             //验证失败
            echo "fail";
        }
    }
    
    //巅峰支付回调
    public function  dianfengpaynotify(){
        // file_put_contents("dianfengpaynotify.txt",json_encode($_REQUEST).PHP_EOL, FILE_APPEND);
        $config = Db::name('zhifu')->where('id',1)->find();
        $config = unserialize($config['content']);
        
        $returnArray = array( // 返回字段
            "memberid" => $_REQUEST["memberid"], // 商户ID
            "orderid" =>  $_REQUEST["orderid"], // 订单号
            "amount" =>  $_REQUEST["amount"], // 交易金额
            "true_amount" =>  $_REQUEST["true_amount"], //实付金额
            "datetime" =>  $_REQUEST["datetime"], // 交易时间
            "transaction_id" =>  $_REQUEST["transaction_id"], // 支付流水号
            "returncode" => $_REQUEST["returncode"],
        );
        $md5key = $config['wxapikey'];
        ksort($returnArray);
        reset($returnArray);
        $md5str = "";
        foreach ($returnArray as $key => $val) {
            $md5str = $md5str . $key . "=" . $val . "&";
        }
        $sign = strtoupper(md5($md5str . "key=" . $md5key));
        
        
        if($sign == $_REQUEST['sign']) {//验证成功
            //获取支付宝的通知返回参数，可参考技术文档中服务器异步通知参数列表
        	//商户订单号
        	$out_trade_no  = $_REQUEST['orderid']; //商户订单号
        
        	//彩虹易支付交易号
        	$trade_no      = $_REQUEST['transaction_id'];
            
            $shijian = date('Y-m-d H:i:s' , time());
                
                $trade_no     = $trade_no;//彩虹订单号
            	$out_trade_no = $out_trade_no;//系统订单号
                $money        = $_REQUEST['amount'];//订单金额
    
    	    
        	    $shijian      = date('Y-m-d H:i:s' , time());
                $out_trade_no = $out_trade_no; //
                $weixin       = $trade_no; //微信订单号
                $cymoney      = $money;
                $orderNo      = $out_trade_no; //我提交的订单号
                
                $order = Cache::store('redis')->get($orderNo);
        		
        		if($order['money'] != $cymoney){
        		   	 exit("签名失败");
        		}
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                    
                                    //总代费用
                                    if($user['zong_id'] !== 0){
                                        $zong_info = Db::name('member')->where(['id'=>$user['zong_id'],'status_zong'=>1,'status'=>1])->find();
                                        
                                        if($zong_info){
                                            $zong_money = ($money2 * ($user['txfeilv'] - $zong_info['txfeilv']) / 100);
                                        }
                                        Db::name("member")->where(['id' => $zong_info['id']])->setInc('money',$zong_money);
                                        $data = [];
                                        $data['zyid'] = $zyid;
                                        $data['userid'] = $zong_info['id'];
                                        $data['zymc'] = "下线收益所得";
                                        $data['ddh'] = $ddh;
                                        $data['money'] = $zong_money;
                                        $data['shijian'] = $shijian;
                                        $data['wxddh'] = $weixin;
                                        $data['type'] = $order['type'];
                                        $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                        $data['order_type'] = 3;
                                        Db::name("dingdan")->insert($data);
                                    }
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    }
        	// 成功， 成功逻辑
            exit("OK");
        }else{
             //验证失败
            echo "fail";
        }
    }
    
    //冈本支付回调
    public function  gangbenpaynotify(){
        $config = Db::name('zhifu')->where('id',3)->find();
        $config = unserialize($config['content']);
        $appSecret = $config['wxapikey'];
        $bodyJson['amount'] = input("amount");
    	$bodyJson['merchantOrderCode'] = input("merchantOrderCode");
    	$bodyJson['platformOrderCode'] = input("platformOrderCode");
    	$bodyJson['status'] = input("status");
    	
    	$signStr = '';
        foreach ($bodyJson as $key => $value){
            $signStr .= $key . '=' . $value;
        }
        $signStr .= 'key=' . $appSecret;
        $signStr = md5($signStr);
        if($signStr == input("sign")) {//验证成功
            //获取支付宝的通知返回参数，可参考技术文档中服务器异步通知参数列表
        	//商户订单号
        	$out_trade_no  = input("merchantOrderCode"); //商户订单号
        
        	//彩虹易支付交易号
        	$trade_no      = input("platformOrderCode");
            
            $shijian = date('Y-m-d H:i:s' , time());
                
                $trade_no     = $trade_no;//彩虹订单号
            	$out_trade_no = $out_trade_no;//系统订单号
                $money        = $bodyJson['amount']/100;//订单金额
    
    	    
        	    $shijian      = date('Y-m-d H:i:s' , time());
                $out_trade_no = $out_trade_no; //
                $weixin       = $trade_no; //微信订单号
                $cymoney      = $money;
                $orderNo      = $out_trade_no; //我提交的订单号
                
                $order = Cache::store('redis')->get($orderNo);
        		
        		if($order['money'] != $cymoney){
        		   	 exit("签名失败");
        		}
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                    
                                    //总代费用
                                    if($user['zong_id'] !== 0){
                                        $zong_info = Db::name('member')->where(['id'=>$user['zong_id'],'status_zong'=>1,'status'=>1])->find();
                                        
                                        if($zong_info){
                                            $zong_money = ($money2 * ($user['txfeilv'] - $zong_info['txfeilv']) / 100);
                                        }
                                        Db::name("member")->where(['id' => $zong_info['id']])->setInc('money',$zong_money);
                                        $data = [];
                                        $data['zyid'] = $zyid;
                                        $data['userid'] = $zong_info['id'];
                                        $data['zymc'] = "下线收益所得";
                                        $data['ddh'] = $ddh;
                                        $data['money'] = $zong_money;
                                        $data['shijian'] = $shijian;
                                        $data['wxddh'] = $weixin;
                                        $data['type'] = $order['type'];
                                        $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                        $data['order_type'] = 3;
                                        Db::name("dingdan")->insert($data);
                                    }
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    }
        	// 成功， 成功逻辑
            echo 'SUCCESS';
        }else{
             //验证失败
            echo "fail";
        }
    }
    //冈本金蝶支付回调
    public function  gangbenpaynotifyjd(){
        $config = Db::name('zhifu')->where('id',4)->find();
        $config = unserialize($config['content']);
        $appSecret = $config['wxapikey'];
        $bodyJson['amount'] = input("amount");
    	$bodyJson['merchantOrderCode'] = input("merchantOrderCode");
    	$bodyJson['platformOrderCode'] = input("platformOrderCode");
    	$bodyJson['status'] = input("status");
    	
    	$signStr = '';
        foreach ($bodyJson as $key => $value){
            $signStr .= $key . '=' . $value;
        }
        $signStr .= 'key=' . $appSecret;
        $signStr = md5($signStr);
        if($signStr == input("sign")) {//验证成功
            //获取支付宝的通知返回参数，可参考技术文档中服务器异步通知参数列表
        	//商户订单号
        	$out_trade_no  = input("merchantOrderCode"); //商户订单号
        
        	//彩虹易支付交易号
        	$trade_no      = input("platformOrderCode");
            
            $shijian = date('Y-m-d H:i:s' , time());
                
                $trade_no     = $trade_no;//彩虹订单号
            	$out_trade_no = $out_trade_no;//系统订单号
                $money        = $bodyJson['amount']/100;//订单金额
    
    	    
        	    $shijian      = date('Y-m-d H:i:s' , time());
                $out_trade_no = $out_trade_no; //
                $weixin       = $trade_no; //微信订单号
                $cymoney      = $money;
                $orderNo      = $out_trade_no; //我提交的订单号
                
                $order = Cache::store('redis')->get($orderNo);
        		
        		if($order['money'] != $cymoney){
        		   	 exit("签名失败");
        		}
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                    
                                    //总代费用
                                    if($user['zong_id'] !== 0){
                                        $zong_info = Db::name('member')->where(['id'=>$user['zong_id'],'status_zong'=>1,'status'=>1])->find();
                                        
                                        if($zong_info){
                                            $zong_money = ($money2 * ($user['txfeilv'] - $zong_info['txfeilv']) / 100);
                                        }
                                        Db::name("member")->where(['id' => $zong_info['id']])->setInc('money',$zong_money);
                                        $data = [];
                                        $data['zyid'] = $zyid;
                                        $data['userid'] = $zong_info['id'];
                                        $data['zymc'] = "下线收益所得";
                                        $data['ddh'] = $ddh;
                                        $data['money'] = $zong_money;
                                        $data['shijian'] = $shijian;
                                        $data['wxddh'] = $weixin;
                                        $data['type'] = $order['type'];
                                        $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                        $data['order_type'] = 3;
                                        Db::name("dingdan")->insert($data);
                                    }
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    }
        	// 成功， 成功逻辑
            echo 'SUCCESS';
        }else{
             //验证失败
            echo "fail";
        }
    }
    
    //618支付回调
    public function  pay618paynotify(){
        // require_once("./extend/618pay/vendor/autoload.php");
        require_once("./extend/618pay/Service/RSAService.php");
        require_once("./extend/618pay/Service/ApiService.php");
        $result = json_decode(file_get_contents('php://input'), true);
        $api = new \ApiService();
        $config = $api->config;
        
        $verfiyStatus = $api->verfiysign618($result, $config['platform_public_key'], $result['sign'], $result['sign_type']);
        if($verfiyStatus) {//验证成功
            //获取支付宝的通知返回参数，可参考技术文档中服务器异步通知参数列表
        	//商户订单号
        	$out_trade_no  = $result['out_trade_no']; //商户订单号
        
        	//彩虹易支付交易号
        	$trade_no      = $result['order_num'];
            
            $shijian = date('Y-m-d H:i:s' , time());
                
                $trade_no     = $trade_no;//彩虹订单号
            	$out_trade_no = $out_trade_no;//系统订单号
                $money        = $result['money'];//订单金额
    
    	    
        	    $shijian      = date('Y-m-d H:i:s' , time());
                $out_trade_no = $out_trade_no; //
                $weixin       = $trade_no; //微信订单号
                $cymoney      = $money;
                $orderNo      = $out_trade_no; //我提交的订单号
                
                $order = Cache::store('redis')->get($orderNo);
        		
        		if($order['money'] != $cymoney){
        		   	 exit("签名失败");
        		}
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                    
                                    //总代费用
                                    if($user['zong_id'] !== 0){
                                        $zong_info = Db::name('member')->where(['id'=>$user['zong_id'],'status_zong'=>1,'status'=>1])->find();
                                        
                                        if($zong_info){
                                            $zong_money = ($money2 * ($user['txfeilv'] - $zong_info['txfeilv']) / 100);
                                        }
                                        Db::name("member")->where(['id' => $zong_info['id']])->setInc('money',$zong_money);
                                        $data = [];
                                        $data['zyid'] = $zyid;
                                        $data['userid'] = $zong_info['id'];
                                        $data['zymc'] = "下线收益所得";
                                        $data['ddh'] = $ddh;
                                        $data['money'] = $zong_money;
                                        $data['shijian'] = $shijian;
                                        $data['wxddh'] = $weixin;
                                        $data['type'] = $order['type'];
                                        $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                        $data['order_type'] = 3;
                                        Db::name("dingdan")->insert($data);
                                    }
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    }
        	// 成功， 成功逻辑
            echo 'SUCCESS';
        }else{
             //验证失败
            echo "fail";
        }
    }
    
    //蘑菇支付回调
    public function  mogupaynotify(){
        // file_put_contents("mogupaynotify.txt",json_encode($_GET).PHP_EOL, FILE_APPEND);
    	//商户订单号
    	$out_trade_no  = $_GET['out_trade_no'];
    	//彩虹易支付交易号
    	$trade_no      = $_GET['trade_no'];
    	//交易状态
    	$trade_status  = $_GET['trade_status'];
    	//支付方式
    	$type = $_GET['type'];
    
    	if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
    	    
    	    $shijian = date('Y-m-d H:i:s' , time());
            
            $trade_no     = $trade_no;//彩虹订单号
        	$out_trade_no = $out_trade_no;//系统订单号
            $money        = $_GET['money'];//订单金额
	    
    	    $shijian      = date('Y-m-d H:i:s' , time());
            $out_trade_no = $out_trade_no; //
            $weixin       = $trade_no; //微信订单号
            $cymoney      = $money;
            $orderNo      = $out_trade_no; //我提交的订单号
            
            $order = Cache::store('redis')->get($orderNo);
        		
    		if($order['money'] != $cymoney){
    		   	 exit("签名失败");
    		}
            // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
            
            $userid = $order['userid'];
            
            
            $zyid = $order['zyid'];
            $ip = $order['ip'];
            $ddh = $orderNo;
            $qudao = $ddh;
            $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
            if (!empty($ipz))
            {
                
                exit;
            }
            
             if($order['order_type'] == 2){
                Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
            }
            
            if(Cache::store('redis')->has($order['uopenid'])){

                $zyidstr = Cache::store('redis')->get($order['uopenid']);
              
                $zyidstr = $zyidstr.','.$zyid;
                
                Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
            }else{
                
                Cache::store('redis')->set($order['uopenid'],$zyid,604800);
               
            }
            Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                $kl = Db::name("kou")->where(['userid' => $userid])->find();
                $ns = $kl['ns'];
                if (!empty($kl))
                {
                    $cs = $kl['cs'] - 1;
                    if ($cs <= 0)
                    {
                        $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                        // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                         
                        // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                        $zymc = $shipin['name'];
                        $user = Db::name("member")->where(['id' => $userid])->find();
                        $name = $user['nickname'];
                        $data = [];
                        $data['name'] = $name;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh;
                        $data['qudao'] = $qudao;
                        $data['money'] = $cymoney;
                        $data['shijian'] = $shijian;
                        $data['zymc'] = $zymc;
                        $data['type'] = $order['type'];
                        $data['order_type'] = $order['order_type'];
                        Db::name("kl")->insert($data);
                        Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                        // 不扣量
                        // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                        //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                        // //
                        $ddh2 = substr($ddh, 0, 10);
                        $data = [];
                        $data['ip'] = $ip;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh2;
                        $data['zyid'] = $zyid;
                        $data['ddh2'] = $ddh;
                        $data['zt'] = "已付";
                        $data['shijian'] = time();
                        $data['openid']  = $order['uopenid'];
                        // $data['zftd']     = $order['zftd'];
                        $data['type'] = $order['type'];
                        $data['uopenid']  = $order['uopenid'];
                        $data['end_time']  = time() + 86400;
                        $data['order_type'] = $order['order_type'];
                        Db::name("ip")->insert($data);
                    }
                    else
                    {
                        Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                
                                //总代费用
                                if($user['zong_id'] !== 0){
                                    $zong_info = Db::name('member')->where(['id'=>$user['zong_id'],'status_zong'=>1,'status'=>1])->find();
                                    
                                    if($zong_info){
                                        $zong_money = ($money2 * ($user['txfeilv'] - $zong_info['txfeilv']) / 100);
                                    }
                                    Db::name("member")->where(['id' => $zong_info['id']])->setInc('money',$zong_money);
                                    $data = [];
                                    $data['zyid'] = $zyid;
                                    $data['userid'] = $zong_info['id'];
                                    $data['zymc'] = "下线收益所得";
                                    $data['ddh'] = $ddh;
                                    $data['money'] = $zong_money;
                                    $data['shijian'] = $shijian;
                                    $data['wxddh'] = $weixin;
                                    $data['type'] = $order['type'];
                                    $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                    $data['order_type'] = 3;
                                    Db::name("dingdan")->insert($data);
                                }
                            }
                            
                        
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']   = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
                    // 不扣量
                    // 代理ID没添加扣量参数
                }
                else
                { 
                    // 写自己的数据库
                    $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                    if (empty($row))
                    { 
                        // /更新会员金额
                        $user = Db::name("member")->where(['id' => $userid])->find();
                        if (!empty($user))
                        {
                            if ($cymoney < 1)
                            {
                                $money2 = $cymoney;
                            }
                            else
                            {
                                $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                            }
                            $money = $user['money'] + $money2;
                            Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                        }
                        $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                        // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                        $zymc = $shipin['name'];
                        // if (!empty($shipin))
                        // {
                        //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                        // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                        // }
                        $data = [];
                        $data['zyid'] = $zyid;
                        $data['userid'] = $userid;
                        $data['zymc'] = $zymc;
                        $data['ddh'] = $ddh;
                        $data['money'] = $cymoney;
                        $data['shijian'] = $shijian;
                        $data['wxddh'] = $weixin;
                        $data['type'] = $order['type'];
                        $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                        $data['order_type'] = $order['order_type'];
                        Db::name("dingdan")->insert($data);
                        $ddh2 = substr($ddh, 0, 10);
                        $data = [];
                        $data['ip'] = $ip;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh2;
                        $data['zyid'] = $zyid;
                        $data['ddh2'] = $ddh;
                        $data['zt'] = "已付";
                        $data['shijian'] = time();
                        $data['openid']  = $order['uopenid'];
                        $data['type'] = $order['type'];
                        // $data['zftd']     = $order['zftd'];
                        $data['uopenid']  = $order['uopenid'];
                        $data['end_time']  = time() + 86400;
                        $data['order_type'] = $order['order_type'];
                        Db::name("ip")->insert($data);
                    } 
                    // 写自己的数据库
                } 
    	}
    	// 成功， 成功逻辑
        echo 'success';
    
    }
    
    //微信内付
    public function wxnewpay()
    {
        if(!is_weixin()){
            $this->redirect("https://xw.qq.com/");
        }
        if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
                 $ip = getIP();
                 $shouji = 1;
          
        }else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Android')){
               $ip = explode(',', getIP())[0];
               $shouji = 0;
        
         }else{
               $ip = getIP();
               $shouji = 1;
         }
        
        $ubodingdan = trim(htmlspecialchars(input("get.ddh"),ENT_QUOTES)); //提交订单号 . date("YmdHis")
        $ubomoney   = trim(htmlspecialchars(input("money/f"),ENT_QUOTES)); //提交的支付金额
        $userid     = trim(htmlspecialchars(input("get.userid"),ENT_QUOTES)); //提交的用户ID
        $ddh3       = trim(htmlspecialchars(input("ddh"),ENT_QUOTES));
        $zyid       = trim(htmlspecialchars(input("zyid/d"),ENT_QUOTES));
        $code       = trim(htmlspecialchars(input("get.code"),ENT_QUOTES));
        $uopenid    = trim(htmlspecialchars(input("get.uopenid",''),ENT_QUOTES));
        $is_baotian = trim(htmlspecialchars(input("get.is_baotian",0),ENT_QUOTES));
        $b_money    = trim(htmlspecialchars(input("get.b_money"),ENT_QUOTES));
        $sing       = trim(htmlspecialchars(input("sing"),ENT_QUOTES));
        
        if(empty($ubodingdan) || empty($ubomoney) || empty($userid)|| empty($ddh3)|| empty($zyid)|| empty($code)|| empty($uopenid)){
              $this->redirect("https://xw.qq.com/");
        }
        
        $info = Db::name('baotian')->where(['uopenid' => $uopenid])->order('id desc')->find();
        
        if($info && $info['end_time'] > time()){
            $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
            //$ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
            $geturl = "http://".$ename."/index/index/shipinok.html?zyid=" . $info['zyid'] ."&ddh=".$info['orderid']."&uopenid=".$uopenid."&bzyid=".$zyid;
            header('Location:'.$geturl);
            die;
        }
        
        
        // $info = Db::name('dwz')->where(['ddh' => $ddh3])->find();
        
        $info = Db::name('dwz')->where(['ddh' => $ddh3])->find();
        
        
         
        $userid   = $info['userid'];
        
        $jiami_id = $info['jiami'];
        
        //查询是否购买
        session('useridopenid', $uopenid);
        
        if(!preg_match("/^\d+(\.\d+)?$/",$ubomoney)){
            // Db::name('dlfj')->insert(['ip' => $ubomoney,'type' => 11]);
            die('金额错误？');
            
        }
        
        $is_gongzhong = Db::name('uopenid')->where(['uopenid' => $uopenid])->find();
        
        
        $member       = Db::name("member")->where(['id' => $userid])->find();
        
        // $neifu     = Db::name('config')->where(['name' => 'neifu'])->value('value');
        $neifu      = Cache::store('redis')->get('ysneifu');
        
        if($b_money >= 30 && $is_baotian == 1){
            
              $order_type = 2;
              $money      = Db::name('pian')->where(['userid' => $userid])->value('b_money');
             
             
             
              $ubomoney = $money;
              
            //   die('包天功能升级中,请等待开放!');
              if(true){
                //  $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
                $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
           
                  $longurl = "http://".$ename ."/index/pay/saoma.html?userid=" . $jiami_id . '&zyid=' . $zyid . "&code=" . $jiami_id."&uopenid=".$uopenid. '&money=' . $ubomoney."&ddh=".$ddh3."&is_baotian=1"."&b_money=".$b_money;
               
                 header('Location:'.$longurl);
                 exit;
               }
           
             
        }else{
             $order_type = 1;
             $ubomoney = Db::name('pian')->where(['userid' => $userid])->value('money');
            
        }
        
        
       
         if($neifu == 0 || $member['zftd'] == 6 || $info['status'] == 0 || $is_gongzhong){
             
           
               $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
                // $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
                  $longurl = "http://".$ename ."/index/pay/saoma.html?userid=" . $jiami_id . '&zyid=' . $zyid . "&code=" . $jiami_id."&uopenid=".$uopenid. '&money=' . $ubomoney."&ddh=".$ddh3."&is_baotian=0"."&b_money=".$b_money;
                header('Location:'.$longurl);
                exit;
       
        }
    
        
        
        // if($userid == 10027){
        //         //$ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
        //          $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
        //           $longurl = "http://".$ename ."/index/pay/saoma.html?userid=" . $jiami_id . '&zyid=' . $zyid . "&code=" . $jiami_id."&uopenid=".$uopenid. '&money=' . $ubomoney."&ddh=".$ddh3."&is_baotian=0"."&b_money=".$b_money;
        //         header('Location:'.$longurl);
        //         exit;
        // }
        
        
       
        
    
        
        $liebiao = Cache::store('redis')->has('ylgongyou'.$zyid);

		if(!$liebiao || $liebiao === "null"){
		      $liebiao = Db::name("gongyou")->where(['id' => $zyid])->find();
		     
		      Cache::store('redis')->set('ylgongyou'.$zyid,json_encode($liebiao),7879680);
		}
        
        
        $ubodingdannew = $ubodingdan . random(4) . $userid . date("dHis").mt_rand(1,10);
       
       
        $order  = Db::name("order")->where(['orderid' => $ubodingdannew])->field('orderid,id')->find();
       
      
        
    
       
    
       
        if (empty($order))
        {
            $data = [];
            $data['orderid']  = $ubodingdannew;
            $data['ip']       = $ip;
            $data['userid']   = $userid;
            $data['zyid']     = $zyid;
            $data['shijian']  = time();
            $data['money']    = $ubomoney;
            $data['uopenid']  = $uopenid;
            $data['code']     = $code . '|' . $ubodingdan;
            $data['ddh3']     = $ddh3; 
            $data['zftd']     = 1;
            $data['type']     = 1;
            $data['jiami']    = $jiami_id;
            $data['shouji']   = $shouji;
            $data['order_type'] = $order_type;
            $data['sing']       = $sing;
            Cache::store('redis')->set($ubodingdannew,json_encode($data),86400);
            
            Db::name("order")->insert($data);
       
        }
       
            $ubomoney = $ubomoney * 100; 
            
            
            $zhifu = Db::name("zhifu")->where(['id' => 1])->find();
            
            
         
            $content = unserialize($zhifu['content']);
            
          
         
            $xieyi   = "http://";
            
            $ename = $xieyi . $content['gzhename'];
            
            $tzurl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $content['wxappid'] . '&redirect_uri=' . urlencode($ename . "/index/wxpay/wxnewpayuuuuu") . '&response_type=code&scope=snsapi_base&state=' . $ubodingdannew . '&connect_redirect=1#wechat_redirect';
            header('Location:'.$tzurl);
            // $this->redirect($tzurl);
            exit;
          
            exit;
          
      
       
    }
    
    //七七扫码支付
    public function saoma(){
        
       
        
        if(!is_weixin()){
            $this->redirect("https://xw.qq.com/");
        }
        if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
                 $ip = getIP();
                 
                 $shouji = 1;
          
        }else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Android')){
              $ip = explode(',', getIP())[0];
              $shouji = 0;
        
        }else{
              $ip = getIP();
              $shouji = 1;
        }
       
        $ubodingdan = trim(htmlspecialchars(input("ddh"),ENT_QUOTES)); //提交订单号 . date("YmdHis")
        $ubomoney   = trim(htmlspecialchars(input("money/f"),ENT_QUOTES)); //提交的支付金额
        $userid     = trim(htmlspecialchars(input("userid"),ENT_QUOTES)); //提交的用户ID
        $ddh3       = trim(htmlspecialchars(input("ddh"),ENT_QUOTES));
        $zyid       = trim(htmlspecialchars(input("zyid/d"),ENT_QUOTES));
        $code       = trim(htmlspecialchars(input("code"),ENT_QUOTES));
        $uopenid    = trim(htmlspecialchars(input("uopenid",''),ENT_QUOTES));
        $pid        = trim(htmlspecialchars(input("pid",''),ENT_QUOTES));
        $is_baotian = trim(htmlspecialchars(input("is_baotian",0),ENT_QUOTES));
        $b_money    = trim(htmlspecialchars(input("b_money"),ENT_QUOTES));
        
      
        
        if(empty($ubodingdan) || empty($ubomoney) || empty($userid)|| empty($ddh3)|| empty($zyid)|| empty($code)|| empty($uopenid)){
              $this->redirect("https://xw.qq.com/");
        }
        $yifutime = time() - intval(24) * 3600;
        
        $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
         
        session('useridopenid', $uopenid);
        //  $ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
         $info = Db::name('baotian')->where(['uopenid' => $uopenid])->order('id desc')->find();
        
        if($info && $info['end_time'] > time()){
            //$ename = Db::name('ename')->where(['status' => 1, 'zt' => 1,'type' => 3])->value('ename');
            $geturl = "http://" . $ename . "/index/index/shipinok.html?zyid=" . $info['zyid'] ."&ddh=".$info['orderid']."&uopenid=".$uopenid."&bzyid=".$zyid;
            $this->redirect($geturl);
        }
      

        
        if(empty($ubodingdan) || empty($ubomoney) || empty($userid) || empty($ddh3) || empty($zyid) || empty($code) || empty($uopenid)){
           
            
             die('参数错误,请重新进入1？');
            
        }
        
         $info = Db::name('dwz')->where(['ddh' => $ddh3])->find();
        
         $jiami_id = $userid;
        
         $userid = $info['userid'];
         
         //查询是否购买
        
         $liebiao = Cache::store('redis')->has('ylgongyou'.$zyid);

		if(!$liebiao || $liebiao === "null"){
		      $liebiao = Db::name("gongyou")->where(['id' => $zyid])->find();
		      if(empty($liebiao)){
		           $liebiao = Db::name("gongyou_copy1")->where(['id' => $zyid])->find();
		      }
		      Cache::store('redis')->set('ylgongyou'.$zyid,json_encode($liebiao),7879680);
		}
		
		 $neifu     = Db::name('config')->where(['name' => 'neifu'])->value('value');
        
        if($neifu == 1){
            
             if($b_money >= 30 && $is_baotian == 1){
                    $longurl = "http://".$ename ."/index/newpay/newhomeyongshun.html?userid=" . $jiami_id . '&zyid=' . $zyid . "&code=" . $jiami_id."&uopenid=".$uopenid. '&money=' . $ubomoney."&ddh=".$ddh3."&is_baotian=1"."&b_money=".$b_money;
                }else{
                    $longurl = "http://".$ename ."/index/newpay/newhomeyongshun.html?userid=" . $jiami_id . '&zyid=' . $zyid . "&code=" . $jiami_id."&uopenid=".$uopenid. '&money=' . $ubomoney."&ddh=".$ddh3;
                }
            
        }
         
       
        
        $member = Cache::store('redis')->get("ysmember".$userid);
        
      
        if($b_money >= 30 && $is_baotian == 1){
            
            // die('包天功能升级中,请等待开放!');
             $order_type = 2;
             $money      = Db::name('pian')->where(['userid' => $userid])->value('b_money');
             
            //  if($money != $b_money){
               
            //      die('参数错误');
                 
            //  }
             
              $ubomoney = $money;
             
        }else{
            
            $money = Cache::store('redis')->get("ysmoney".$userid);
            
            if($money != $ubomoney){
                 $ubomoney = Db::name('pian')->where(['userid' => $userid])->value('money');
                 Cache::store('redis')->set("ysmoney".$userid,$ubomoney,77879680);
            }
            $order_type = 1;
            
        }
       
        
         
        $ubomoney = ceil($ubomoney);
        
        
        
        
        
        $ubodingdannew = $ubodingdan . random(4) . $userid . date("dHis");
       
       
        $order = Db::name("order")->where(['orderid' => $ubodingdannew])->field('orderid,id')->find();
        
      
       
        if (empty($order))
        {
            $data = [];
            $data['orderid'] = $ubodingdannew;
            $data['ip'] = $ip;
            $data['userid'] = $userid;
            $data['zyid'] = $zyid;
            $data['shijian'] = time();
            $data['money'] = $ubomoney;
            $data['uopenid'] = $uopenid;
            $data['code']    = $code . '|' . $ubodingdan;
            $data['ddh3']    = $ddh3; 
            $data['type']    = 2; //扫码支付
            $data['jiami']    = $jiami_id; 
            $data['order_type'] = $order_type;
            
            Cache::store('redis')->set($ubodingdannew,json_encode($data),86400);
            Db::name("order")->insert($data);
        }
        
            $ubomoney = $ubomoney * 100;
          
            $url = Db::name('config')->where(['name' => 'bei_url'])->value('value');
           // $url = "pay.omo360.com"; //支付网关联系客服获取
            /*************************************************************************************************************/
            $paydata = array (
            		'mchId' => "600500017", //商户ID，后台提取
            		'billNo' => $ubodingdannew, //商户订单号
            		'totalAmount' => $ubomoney, //金额
            		'billDesc' => "购买视频", //商品名称
            		'way' => "qrcode", //微信扫码模式
            		'payment' => 'wechat', //微信支付
            		'notifyUrl' => "http://".$ename."/index/pay/saomahuidiao", //回调地址
            		'returnUrl' => "http://".$ename."/index/index/shipinok", //同步跳转
            		'attach' => '',
            		"accKey" => "" //收款账号
            );
           
            $Md5key = '53d279dab0174ac856b74ca0a657260da0e5040903c7336aaaa0c42e0d660493'; //签名密钥，后台提取
            $paydata ['sign'] = saomamarkSign( $paydata, $Md5key );
            $payUrl = "http://$url/game/unifiedorder"; //请求订单地址
            $datas = newposturl($payUrl,$paydata);
      
            // $log_name = 'send.txt';
            // writefile($log_name, "【接收到的notify通知】:\n" . print_r(json_encode ( $paydata ),true) . "\n");
            // $datas = json_decode ( $ret, true );
            
            if ($datas ['code'] == 0) {
            	$payCode = $datas ['result'] ['payInfo']; //支付二维码
            } else {
                
                if($b_money >= 30 && $is_baotian == 1){
                    $longurl = "http://".$ename ."/index/fang/dalaohu.html?userid=" . $jiami_id . '&zyid=' . $zyid . "&code=" . $jiami_id."&uopenid=".$uopenid. '&money=' . $ubomoney."&ddh=".$ddh3."&is_baotian=1"."&b_money=".$b_money;
                }else{
                    $longurl = "http://".$ename ."/index/fang/dalaohu.html?userid=" . $jiami_id . '&zyid=' . $zyid . "&code=" . $jiami_id."&uopenid=".$uopenid. '&money=' . $ubomoney."&ddh=".$ddh3;
                }
                $this->redirect($longurl);
            	exit ( $datas ['message'] );
            }
            
    
            $url = "http://" . $ename . "/index/index/shipinok.html?ddh=" . $ubodingdannew;
            
            $this->assign('url', $url);
            $this->assign('billNo', $ubodingdannew);
            
           
            $this->assign('payCode', $payCode);
            return $this->fetch('pay/saoma');
        
    }
    
    //扫码回调
    public function saomahuidiao(){
           
            $notifyData = [
                'mchId'       => $_REQUEST['mchId'],
                'tradeNo'     => $_REQUEST['tradeNo'],
                'billNo'      => $_REQUEST['billNo'],
                'sub_op'      => $_REQUEST['sub_op'],
                'totalAmount' => $_REQUEST['totalAmount'],
                'transferId'  => $_REQUEST['transferId'],
                'way'         => $_REQUEST['way'],
                'payment'     => $_REQUEST['payment'],
                'code'        => $_REQUEST['code'],
                'acc_key'     => $_REQUEST['acc_key'],
                'acc_name'    => $_REQUEST['acc_name'],
                'attach'      => $_REQUEST['attach'],
                'tradeStatus' => $_REQUEST['tradeStatus'],
                'create_at'   => $_REQUEST['create_at'],
                'payTime'     => $_REQUEST['payTime'],
            ];
            
            $order_no     = $_REQUEST["billNo"]; //商户订单号
            $tradeStatus  = $_REQUEST["tradeStatus"]; //支付成功状态
            $sign         = $_REQUEST["sign"]; //验证签名 
            $cymoney      = $_REQUEST["totalAmount"]; 
           
            $Md5key   = '53d279dab0174ac856b74ca0a657260da0e5040903c7336aaaa0c42e0d660493'; //签名密钥，后台提取
        
        // $log_name = "saoma.log"; //log文件路径
        // writefile($log_name, "【接收到的notify通知】:\n" . print_r($_REQUEST,true) . "\n");
        if ($tradeStatus==1){
        	$resSign = saomamarkSign($notifyData,$Md5key);
        	if($sign != $resSign){
        	    exit("签名失败");
        	}
        // 	$log_name = "saoma2.log"; //log文件路径
            // writefile($log_name, "【签名失败】:\n" . print_r($_REQUEST,true) . "\n");
        // 	if ($sign == $resSign){
        	    
        	    
        	    $shijian = date('Y-m-d H:i:s' , time());
                $out_trade_no = $order_no; //
                $weixin       = $tradeStatus; //微信订单号
                $cymoney = $cymoney;
                $orderNo = $order_no; //我提交的订单号
                // $openid  = $notify->data["openid"];//微信openid
                
                // $order = Cache::store('redis')->get($orderNo);
        		$order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
        		
        		if($order['money'] != $cymoney && $cymoney < 12){
        		   	 exit("签名失败");
        		}
        		
        		if($order['order_type'] == 2 && $cymoney < 30){
        		     exit("签名失败");
        		}
        		
        		if($cymoney < 0){
        		     exit("签名失败");
        		}
        		
        		$cymoney = $cymoney * 0.97;
                
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    exit;
                }
                
                if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                
                
                 Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    // $qik = $ns - 0;
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            //$shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                             $shipin = Db::name("gongyou")->where(['id' => $zyid])->find();
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                           
                           
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    
                                    
                                    $money = $user['money'] + $money2;
                                    
                                    if($money > 0){
                                        Db::name("member")->where(['id' => $userid])->update(['money' => $money]);  
                                    }
                                  
                                }
                                
                            
                                $shipin = Db::name("gongyou")->where(['id' => $zyid])->find();
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                $data['order_type'] = $order['order_type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']  = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                
                                $money = $user['money'] + $money2;
                                    
                                if($money > 0){
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);  
                                }
                            }
                            // $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            $shipin = Db::name("gongyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
             
        		//商户处理订单逻辑
        		echo "SUCCESS";
        // 	} else {
        // 	    $log_name = "saoma2.log"; //log文件路径
        //         writefile($log_name, "【签名失败】:\n" . print_r($_REQUEST,true) . "\n");
        // 		exit("签名失败");
        // 	}
        }
        
    }
    
    
    
     /**
     * @Note  发起支付
     * @param @id          对接ID
     * @param @key          对接Token
     * @param @trade_no   订单号
     * @param @name          商品名称
     * @param @money      金额（元）
     * @param @mchid      商户id (如果为空,则随机选择支付商户)
     * @param @notify_url 异步通知地址
     * @param @return_url 同步支付地址（支付成功后跳转的页面）
     * @param @return string  返回支付链接
     */
    public function mpxxxts_pay($id, $key, $type,$trade_no, $name, $money, $notify_url, $return_url,$payurl, $mchid = '')
    {
        $url = $payurl;
        $url = $url;
        $url = "http://$url/pay/do_pay";
        
        $data = [
            'id'           => $id,
            'out_trade_no' => $trade_no,
            'name'         => $name,
            'type'         => $type,
            'money'        => $money,
            'mchid'        => $mchid,
            'notify_url'   => $notify_url,
            'return_url'   => $return_url,
        ];
        // 参数排序拼接
        $data = array_filter($data);
        ksort($data);
        $str1 = '';
        foreach ($data as $k => $v) {
            $str1 .= '&' . $k . "=" . $v;
        }
        // $str1 = &id=1&mchid=1615764184&money=0.01&name=test&notify_url=http://pay.xxx.com/test/notify&out_trade_no=1635935795845875&type=902
        // 去除 $str1 两头多余的 & 字符 并 md5
        $sign = md5(trim($str1 . $key, '&'));
        $data['sign']      = $sign;
        $data['sign_type'] = 'MD5';
        // post表单提交
        $info = $this->posturl($url, $data);
        if ($info['code'] == 400)
        {
            echo $info['message'];
        }
        else if($info['code'] == 0)
        {
            $url = $info['message'];
            Header("Location: $url");
        }
        exit;
    }
    
    public function posturl($url, $data)
    {
      
        $data        = json_encode($data);
        $headerArray = array("Content-type:application/json;charset='utf-8'", "Accept:application/json");
        $curl        = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headerArray);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($curl, CURLOPT_TIMEOUT, 20);
        $output = curl_exec($curl);
        curl_close($curl);
        return json_decode($output, true);
    }
    
    //嘻嘻哈哈支付回调
    public function tstststiao(){
        
                /*
         * 支付结果接收
         */
        //对接ID
        //对接Token
        $token = '3c9a732a2b0df1687945f8e8450c1daf';
        
        $data['id']           = $_REQUEST['id']; // 对接的id
        $data['trade_no']     = $_REQUEST['trade_no']; // 微信订单号
        $data['out_trade_no'] = $_REQUEST['out_trade_no']; // 订单号
        $data['name']         = $_REQUEST['name']; // 
        $data['money']        = $_REQUEST['money']; // 支付金额
        $data['trade_status'] = $_REQUEST['trade_status']; // TRADE_SUCCESS or TRADE_FAIL
        
        
        $order = Cache::store('redis')->get($data['out_trade_no']);
       
        if(empty($order)){
            echo '签名失败';
            exit;
        }
        
        $data = get_magic_quotes_gpc() ? stripslashes(array_filter($data)) : array_filter($data);
        ksort($data);
        $str1 = '';
        foreach ($data as $k => $v) {
            $str1 .= '&' . $k . "=" . $v;
        }
        $sign = md5(trim($str1 . $token, '&'));
        if ($sign !== $_REQUEST['sign']) {
            // 失败， 失败逻辑
            echo '签名失败';
            exit;
        } else {
         
        	    $shijian = date('Y-m-d H:i:s' , time());
                $out_trade_no = $data['out_trade_no']; //
                $weixin       = $data['trade_no']; //微信订单号
                $cymoney = $data['money'];
                $orderNo = $data['out_trade_no']; //我提交的订单号
                // $openid  = $notify->data["openid"];//微信openid
                $order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
                // $order = Cache::store('redis')->get($orderNo);
        		
        		
        		if($order['money'] != $cymoney && $cymoney < 12){
        		   	 exit("签名失败");
        		}
        		
        	
                
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                $data['sp_type']    = $shipin['type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
      
            // 成功， 成功逻辑
            echo 'success';
        }
        
        
    }
    
   
    
    public function yungetsign($appKey,$param){
    	$signPars = "";
    	ksort($param);
    	foreach ($param as $k => $v) {
    		if ($k!="sign"&&$v!="") {
    			$signPars .= $k . "=" . $v . "&";
    		}
    	}
    	$signPars = rtrim($signPars, '&');
    	$signPars .= $appKey;
    	$sign = md5($signPars);
    	return $sign;
    }
    
    //英雄支付回调
    public function  yinxuongpaynotify(){
        $options = $_GET;
         
    	$oldSign = $options['sign'];
    	unset($options['sign']);
        unset($options['sign_type']);
        $appKey = "zbeK0oF8V8oUT0Oub1xMov8fSS0o1fBb"; 
    	$sign   = $this->yungetsign($appKey,$options);
    	
    	$trade_no     = $options['trade_no'];//永生订单号
    	$out_trade_no = $options['out_trade_no'];//系统订单号
        $money        = $options['money'];//订单金额
    	if($sign ==$oldSign) {
    	    
        	    $shijian = date('Y-m-d H:i:s' , time());
                $out_trade_no = $out_trade_no; //
                $weixin       = $trade_no; //微信订单号
                $cymoney = $money;
                $orderNo = $out_trade_no; //我提交的订单号
                // $openid  = $notify->data["openid"];//微信openid
                
                $order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
                // $order = Cache::store('redis')->get($orderNo);
        		
        		
        		if($order['money'] != $cymoney && $cymoney < 12){
        		   	 exit("签名失败");
        		}
        		
        	
                
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
      
            // 成功， 成功逻辑
            echo 'success';
    	}
		
        
    }
    
    //英雄个码回调
    public function  yinxuongpaygemapaynotify(){
        $options = $_GET;
         
    	$oldSign = $options['sign'];
    	unset($options['sign']);
        unset($options['sign_type']);
        $appKey = "zbeK0oF8V8oUT0Oub1xMov8fSS0o1fBb"; 
    	$sign   = $this->yungetsign($appKey,$options);
    	
    	$trade_no     = $options['trade_no'];//永生订单号
    	$out_trade_no = $options['out_trade_no'];//系统订单号
        $money        = $options['money'];//订单金额
    	if($sign ==$oldSign) {
    	    
        	    $shijian = date('Y-m-d H:i:s' , time());
                $out_trade_no = $out_trade_no; //
                $weixin       = $trade_no; //微信订单号
                $cymoney = $money;
                $orderNo = $out_trade_no; //我提交的订单号
                // $openid  = $notify->data["openid"];//微信openid
                
                $order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
                // $order = Cache::store('redis')->get($orderNo);
        		
        		
        		if($order['money'] != $cymoney && $cymoney < 12){
        		   	 exit("签名失败");
        		}
        		
        	
                
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
      
            // 成功， 成功逻辑
            echo 'success';
    	}
		
        
    }
    
    //老杨支付回调
    
    public function laoyangpaynotify(){
        
        /*
        * 支付结果接收
        */
        //对接ID
        //对接Token
        $token = 'ae6e3d316f5979b4d0';

        $data['callbacks'] = $_REQUEST['callbacks'];    //订单成功标识，必须为“ORDER_SUCCESS”
        $data['partnerid'] = $_REQUEST['partnerid']; //商户ID
        $data['amount'] = number_format(floatval($_REQUEST['amount']), 2, '.', ''); //实付金额（元，两位小数）
        $data['money'] = number_format(floatval($_REQUEST['money']), 2, '.', ''); //订单金额（元，两位小数）
        $data['sysorderno'] = $_REQUEST['sysorderno']; //系统订单号
        $data['pay_type'] = $_REQUEST['pay_type']; //支付类型
        $data['pay_time'] = $_REQUEST['pay_time']; //支付时间
        $data['out_trade_no'] = $_REQUEST['out_trade_no']; //商户订单号
        $data['version'] = $_REQUEST['version']; //支付版本号
        $data['status'] = $_REQUEST['status']; //订单状态
        $remark = $_REQUEST['remark']; //备注信息
        $data['sign'] = $_REQUEST['sign']; //md5密钥（KEY）
        
        
        
        
        // $data['callbacks'] = "ORDER_SUCCESS";    //订单成功标识，必须为“ORDER_SUCCESS”
        // $data['partnerid'] = "2"; //商户ID
        // $data['amount']    = "5.00"; //实付金额（元，两位小数）
        // $data['money']     = "5.00"; //订单金额（元，两位小数）
        // $data['sysorderno'] = "EC03608190870267"; //系统订单号
        // $data['pay_type'] = "wechat_public"; //支付类型
        // $data['pay_time'] = "1638460827"; //支付时间
        // $data['out_trade_no'] = "FDC9Em8ZjbQnn31002703000018"; //商户订单号
        // $data['version'] = "1.0"; //支付版本号
        // $data['status'] = "4"; //订单状态
        // $remark = $_REQUEST['remark']; //备注信息
        // $data['sign'] = "9D0D2A034C3FF2BF2EC310014725AF67"; //md5密钥（KEY）
        
        
        // $log_name = "laoyang1111111.log"; //log文件路径
        // file_put_contents($log_name,"minipay".json_encode($data ,1).PHP_EOL,FILE_APPEND);
        
        
       if ($data['callbacks'] != "ORDER_SUCCESS") {
         
            echo "order error";
            exit;
        }
        
        if (laoyangverifySign($data,$token) != true) {
            // 失败， 失败逻辑
            echo '签名错误';
            exit;
        } else {
        
                $shijian = date('Y-m-d H:i:s' , time());
                $out_trade_no = $data['out_trade_no']; //
                $weixin       = $data['sysorderno']; //微信订单号
                $cymoney      = $data['money'];
                $orderNo      = $data['out_trade_no']; //我提交的订单号
                // $openid  = $notify->data["openid"];//微信openid
                $order        = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
                // $order = Cache::store('redis')->get($orderNo);
                
                
                if($order['money'] != $cymoney && $cymoney < 12){
                        exit("签名失败");
                }
                
            
                
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                            
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                $data['sp_type']    = $shipin['type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 

            // 成功， 成功逻辑
            echo 'success';
        }


    }
    
    
    
    
        //易达云闪付回调
    public function  shangyigemapaynotifytwo(){
        require_once("./extend/caihongtwo/epay.config.php");
        require_once("./extend/caihongtwo/lib/epay_notify.class.php");
        
        //计算得出通知验证结果
        $alipayNotify = new \AlipayNotify($alipay_config);
        $verify_result = $alipayNotify->verifyNotify();
        if($verify_result) {//验证成功
            //获取支付宝的通知返回参数，可参考技术文档中服务器异步通知参数列表
        	//商户订单号
        	$out_trade_no  = $_GET['out_trade_no'];
        
        	//彩虹易支付交易号
        
        	$trade_no      = $_GET['trade_no'];
        
        	//交易状态
        	$trade_status  = $_GET['trade_status'];
        
        	//支付方式
        	$type = $_GET['type'];
        
        
        	if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
        	    $shijian = date('Y-m-d H:i:s' , time());
                
                $trade_no     = $trade_no;//彩虹订单号
            	$out_trade_no = $out_trade_no;//系统订单号
                $money        = $_GET['money'];//订单金额
    
    	    
        	    $shijian      = date('Y-m-d H:i:s' , time());
                $out_trade_no = $out_trade_no; //
                $weixin       = $trade_no; //微信订单号
                $cymoney      = $money;
                $orderNo      = $out_trade_no; //我提交的订单号
                
                $order = Cache::store('redis')->get($orderNo);
        		
        		if($order['money'] != $cymoney && $cymoney < 12){
        		   	 exit("签名失败");
        		}
        		
        	
                
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
        	}
        	// 成功， 成功逻辑
            echo 'success';
        }else{
             //验证失败
            echo "fail";
        }
    }
    
    
  
   //蜡笔支付回调
    public function llbb11111payhuitiao()
    {
        
        $token = '1634222415WZ05qzElRcxpZZqhU42NQR';
        
        $data['order']          = $_REQUEST['order']; // 订单号
        $data['fee']            = $_REQUEST['fee']; // 
        $data['randStr']        = $_REQUEST['randStr']; // 支付金额
    
        
        $data = get_magic_quotes_gpc() ? stripslashes(array_filter($data)) : array_filter($data);
        ksort($data);
       
        $sign  = taoqimaomk($data,$token);
        
        if ($sign !== $_REQUEST['sign']) {
            // 失败， 失败逻辑
            echo '签名失败';
            exit;
        } else {
    	    $shijian = date('Y-m-d H:i:s' , time());
            $out_trade_no =  $data['order']; //
            $weixin       =  $data['order']; //微信订单号
            $cymoney      = $data['fee'] / 100;
            $orderNo      =  $data['order']; //我提交的订单号
            // $openid  = $notify->data["openid"];//微信openid
            
            //$order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
    		$order = Cache::store('redis')->get($orderNo);
    		
    		if($order['money'] != $cymoney && $cymoney < 12){
    		   	 exit("签名失败");
    		}
        		
        	
                
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
            $userid = $order['userid'];
            
            
            $zyid = $order['zyid'];
            $ip = $order['ip'];
            $ddh = $orderNo;
            $qudao = $ddh;
            $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
            if (!empty($ipz))
            {
                
                exit;
            }
                
            if($order['order_type'] == 2){
                Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
            }
            
            if(Cache::store('redis')->has($order['uopenid'])){

                $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                $zyidstr = $zyidstr.','.$zyid;
                    
                Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
            }else{
                    
                Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
            }
            Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
            $kl = Db::name("kou")->where(['userid' => $userid])->find();
            $ns = $kl['ns'];
            if (!empty($kl))
                {
                    $cs = $kl['cs'] - 1;
                    if ($cs <= 0)
                    {
                        $shipin = Cache::store('redis')->get('gongyou'.$zyid);
                        // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                         
                        // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                        $zymc = $shipin['name'];
                        $user = Db::name("member")->where(['id' => $userid])->find();
                        $name = $user['nickname'];
                        $data = [];
                        $data['name'] = $name;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh;
                        $data['qudao'] = $qudao;
                        $data['money'] = $cymoney;
                        $data['shijian'] = $shijian;
                        $data['zymc'] = $zymc;
                        $data['type'] = $order['type'];
                        $data['order_type'] = $order['order_type'];
                        Db::name("kl")->insert($data);
                        Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                        // 不扣量
                        // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                        //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                        // //
                        $ddh2 = substr($ddh, 0, 10);
                        $data = [];
                        $data['ip'] = $ip;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh2;
                        $data['zyid'] = $zyid;
                        $data['ddh2'] = $ddh;
                        $data['zt'] = "已付";
                        $data['shijian'] = time();
                        $data['openid']  = $order['uopenid'];
                        // $data['zftd']     = $order['zftd'];
                        $data['type'] = $order['type'];
                        $data['uopenid']  = $order['uopenid'];
                        $data['end_time']  = time() + 86400;
                        $data['order_type'] = $order['order_type'];
                        $data['sp_type']    = $shipin['type'];
                        Db::name("ip")->insert($data);
                    }
                    else
                    {
                        Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            
                        
                            $shipin = Cache::store('redis')->get('gongyou'.$zyid);
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']   = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
                    // 不扣量
                    // 代理ID没添加扣量参数
                }
                else
                { 
                    // 写自己的数据库
                    $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                    if (empty($row))
                    { 
                        // /更新会员金额
                        $user = Db::name("member")->where(['id' => $userid])->find();
                        if (!empty($user))
                        {
                            if ($cymoney < 1)
                            {
                                $money2 = $cymoney;
                            }
                            else
                            {
                                $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                            }
                            $money = $user['money'] + $money2;
                            Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                        }
                        $shipin = Cache::store('redis')->get('gongyou'.$zyid);
                        // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                        $zymc = $shipin['name'];
                        // if (!empty($shipin))
                        // {
                        //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                        // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                        // }
                        $data = [];
                        $data['zyid'] = $zyid;
                        $data['userid'] = $userid;
                        $data['zymc'] = $zymc;
                        $data['ddh'] = $ddh;
                        $data['money'] = $cymoney;
                        $data['shijian'] = $shijian;
                        $data['wxddh'] = $weixin;
                        $data['type'] = $order['type'];
                        $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                        $data['order_type'] = $order['order_type'];
                        Db::name("dingdan")->insert($data);
                        $ddh2 = substr($ddh, 0, 10);
                        $data = [];
                        $data['ip'] = $ip;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh2;
                        $data['zyid'] = $zyid;
                        $data['ddh2'] = $ddh;
                        $data['zt'] = "已付";
                        $data['shijian'] = time();
                        $data['openid']  = $order['uopenid'];
                        $data['type'] = $order['type'];
                        // $data['zftd']     = $order['zftd'];
                        $data['uopenid']  = $order['uopenid'];
                        $data['end_time']  = time() + 86400;
                        $data['order_type'] = $order['order_type'];
                        $data['sp_type']    = $shipin['type'];
                        Db::name("ip")->insert($data);
                    } 
                    // 写自己的数据库
                } 
      
            // 成功， 成功逻辑
            echo 'success';
        }
        
        
    }
   
    
    //空空支付回调
    public function kongkongpayhuitiao()
    {
        
        $token = '1638116705e6MNdqr0VXqbwSPivDJhBp';
        
        $data['order']          = $_REQUEST['order']; // 订单号
        $data['fee']            = $_REQUEST['fee']; // 
        $data['randStr']        = $_REQUEST['randStr']; // 支付金额
    
        
        $data = get_magic_quotes_gpc() ? stripslashes(array_filter($data)) : array_filter($data);
        ksort($data);
       
        $sign  = taoqimaomk($data,$token);
        
        if ($sign !== $_REQUEST['sign']) {
            // 失败， 失败逻辑
            echo '签名失败';
            exit;
        } else {
    	    $shijian = date('Y-m-d H:i:s' , time());
            $out_trade_no =  $data['order']; //
            $weixin       =  $data['order']; //微信订单号
            $cymoney      = $data['fee'] / 100;
            $orderNo      =  $data['order']; //我提交的订单号
            // $openid  = $notify->data["openid"];//微信openid
            
            //$order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
    		$order = Cache::store('redis')->get($orderNo);
    		
    		if($order['money'] != $cymoney && $cymoney < 12){
    		   	 exit("签名失败");
    		}
        		
        	
                
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
            $userid = $order['userid'];
            
            
            $zyid = $order['zyid'];
            $ip = $order['ip'];
            $ddh = $orderNo;
            $qudao = $ddh;
            $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
            if (!empty($ipz))
            {
                
                exit;
            }
                
            if($order['order_type'] == 2){
                Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
            }
            
            if(Cache::store('redis')->has($order['uopenid'])){

                $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                $zyidstr = $zyidstr.','.$zyid;
                    
                Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
            }else{
                    
                Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
            }
            Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
            $kl = Db::name("kou")->where(['userid' => $userid])->find();
            $ns = $kl['ns'];
            if (!empty($kl))
                {
                    $cs = $kl['cs'] - 1;
                    if ($cs <= 0)
                    {
                        $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                        // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                         
                        // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                        $zymc = $shipin['name'];
                        $user = Db::name("member")->where(['id' => $userid])->find();
                        $name = $user['nickname'];
                        $data = [];
                        $data['name'] = $name;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh;
                        $data['qudao'] = $qudao;
                        $data['money'] = $cymoney;
                        $data['shijian'] = $shijian;
                        $data['zymc'] = $zymc;
                        $data['type'] = $order['type'];
                        $data['order_type'] = $order['order_type'];
                        Db::name("kl")->insert($data);
                        Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                        // 不扣量
                        // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                        //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                        // //
                        $ddh2 = substr($ddh, 0, 10);
                        $data = [];
                        $data['ip'] = $ip;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh2;
                        $data['zyid'] = $zyid;
                        $data['ddh2'] = $ddh;
                        $data['zt'] = "已付";
                        $data['shijian'] = time();
                        $data['openid']  = $order['uopenid'];
                        // $data['zftd']     = $order['zftd'];
                        $data['type'] = $order['type'];
                        $data['uopenid']  = $order['uopenid'];
                        $data['end_time']  = time() + 86400;
                        $data['order_type'] = $order['order_type'];
                        $data['sp_type']    = $shipin['type'];
                        Db::name("ip")->insert($data);
                    }
                    else
                    {
                        Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            
                        
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']   = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
                    // 不扣量
                    // 代理ID没添加扣量参数
                }
                else
                { 
                    // 写自己的数据库
                    $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                    if (empty($row))
                    { 
                        // /更新会员金额
                        $user = Db::name("member")->where(['id' => $userid])->find();
                        if (!empty($user))
                        {
                            if ($cymoney < 1)
                            {
                                $money2 = $cymoney;
                            }
                            else
                            {
                                $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                            }
                            $money = $user['money'] + $money2;
                            Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                        }
                        $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                        // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                        $zymc = $shipin['name'];
                        // if (!empty($shipin))
                        // {
                        //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                        // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                        // }
                        $data = [];
                        $data['zyid'] = $zyid;
                        $data['userid'] = $userid;
                        $data['zymc'] = $zymc;
                        $data['ddh'] = $ddh;
                        $data['money'] = $cymoney;
                        $data['shijian'] = $shijian;
                        $data['wxddh'] = $weixin;
                        $data['type'] = $order['type'];
                        $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                        $data['order_type'] = $order['order_type'];
                        Db::name("dingdan")->insert($data);
                        $ddh2 = substr($ddh, 0, 10);
                        $data = [];
                        $data['ip'] = $ip;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh2;
                        $data['zyid'] = $zyid;
                        $data['ddh2'] = $ddh;
                        $data['zt'] = "已付";
                        $data['shijian'] = time();
                        $data['openid']  = $order['uopenid'];
                        $data['type'] = $order['type'];
                        // $data['zftd']     = $order['zftd'];
                        $data['uopenid']  = $order['uopenid'];
                        $data['end_time']  = time() + 86400;
                        $data['order_type'] = $order['order_type'];
                        $data['sp_type']    = $shipin['type'];
                        Db::name("ip")->insert($data);
                    } 
                    // 写自己的数据库
                } 
      
            // 成功， 成功逻辑
            echo 'success';
        }
        
        
    }
    
    //悍马支付回调
    public function hanmapaynotice_url()
    {
        
        $token = '1639208192g2tJEo';
        
        $data['order']          = $_REQUEST['order']; // 订单号
        $data['fee']            = $_REQUEST['fee']; // 
        $data['randStr']        = $_REQUEST['randStr']; // 支付金额
    
        
        $data = get_magic_quotes_gpc() ? stripslashes(array_filter($data)) : array_filter($data);
        ksort($data);
       
        $sign  = taoqimaomk($data,$token);
        
        if ($sign !== $_REQUEST['sign']) {
            // 失败， 失败逻辑
            echo '签名失败';
            exit;
        } else {
    	    $shijian = date('Y-m-d H:i:s' , time());
            $out_trade_no =  $data['order']; //
            $weixin       =  $data['order']; //微信订单号
            $cymoney      = $data['fee'] / 100;
            $orderNo      =  $data['order']; //我提交的订单号
            // $openid  = $notify->data["openid"];//微信openid
            
            //$order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
    		$order = Cache::store('redis')->get($orderNo);
    		
    		if($order['money'] != $cymoney && $cymoney < 12){
    		   	 exit("签名失败");
    		}
        		
        	
                
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
            $userid = $order['userid'];
            
            
            $zyid = $order['zyid'];
            $ip = $order['ip'];
            $ddh = $orderNo;
            $qudao = $ddh;
            $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
            if (!empty($ipz))
            {
                
                exit;
            }
                
            if($order['order_type'] == 2){
                Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
            }
            
            if(Cache::store('redis')->has($order['uopenid'])){

                $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                $zyidstr = $zyidstr.','.$zyid;
                    
                Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
            }else{
                    
                Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
            }
            Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
            $kl = Db::name("kou")->where(['userid' => $userid])->find();
            $ns = $kl['ns'];
            if (!empty($kl))
                {
                    $cs = $kl['cs'] - 1;
                    if ($cs <= 0)
                    {
                        $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                        // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                         
                        // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                        $zymc = $shipin['name'];
                        $user = Db::name("member")->where(['id' => $userid])->find();
                        $name = $user['nickname'];
                        $data = [];
                        $data['name'] = $name;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh;
                        $data['qudao'] = $qudao;
                        $data['money'] = $cymoney;
                        $data['shijian'] = $shijian;
                        $data['zymc'] = $zymc;
                        $data['type'] = $order['type'];
                        $data['order_type'] = $order['order_type'];
                        Db::name("kl")->insert($data);
                        Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                        // 不扣量
                        // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                        //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                        // //
                        $ddh2 = substr($ddh, 0, 10);
                        $data = [];
                        $data['ip'] = $ip;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh2;
                        $data['zyid'] = $zyid;
                        $data['ddh2'] = $ddh;
                        $data['zt'] = "已付";
                        $data['shijian'] = time();
                        $data['openid']  = $order['uopenid'];
                        // $data['zftd']     = $order['zftd'];
                        $data['type'] = $order['type'];
                        $data['uopenid']  = $order['uopenid'];
                        $data['end_time']  = time() + 86400;
                        $data['order_type'] = $order['order_type'];
                        $data['sp_type']    = $shipin['type'];
                        Db::name("ip")->insert($data);
                    }
                    else
                    {
                        Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            
                        
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']   = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
                    // 不扣量
                    // 代理ID没添加扣量参数
                }
                else
                { 
                    // 写自己的数据库
                    $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                    if (empty($row))
                    { 
                        // /更新会员金额
                        $user = Db::name("member")->where(['id' => $userid])->find();
                        if (!empty($user))
                        {
                            if ($cymoney < 1)
                            {
                                $money2 = $cymoney;
                            }
                            else
                            {
                                $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                            }
                            $money = $user['money'] + $money2;
                            Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                        }
                        $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                        // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                        $zymc = $shipin['name'];
                        // if (!empty($shipin))
                        // {
                        //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                        // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                        // }
                        $data = [];
                        $data['zyid'] = $zyid;
                        $data['userid'] = $userid;
                        $data['zymc'] = $zymc;
                        $data['ddh'] = $ddh;
                        $data['money'] = $cymoney;
                        $data['shijian'] = $shijian;
                        $data['wxddh'] = $weixin;
                        $data['type'] = $order['type'];
                        $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                        $data['order_type'] = $order['order_type'];
                        Db::name("dingdan")->insert($data);
                        $ddh2 = substr($ddh, 0, 10);
                        $data = [];
                        $data['ip'] = $ip;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh2;
                        $data['zyid'] = $zyid;
                        $data['ddh2'] = $ddh;
                        $data['zt'] = "已付";
                        $data['shijian'] = time();
                        $data['openid']  = $order['uopenid'];
                        $data['type'] = $order['type'];
                        // $data['zftd']     = $order['zftd'];
                        $data['uopenid']  = $order['uopenid'];
                        $data['end_time']  = time() + 86400;
                        $data['order_type'] = $order['order_type'];
                        $data['sp_type']    = $shipin['type'];
                        Db::name("ip")->insert($data);
                    } 
                    // 写自己的数据库
                } 
      
            // 成功， 成功逻辑
            echo 'success';
        }
        
        
    }
  
  
    
    //沈海高速支付回调
    public function shenhaigaosupayhuidiao()
    {
        
        
       
        // $log_name = "taoqimao1111111.log"; //log文件路径
        // file_put_contents($log_name,"minipay".json_encode($_REQUEST ,1).PHP_EOL,FILE_APPEND);
                /*
         * 支付结果接收
         */
        //对接ID
        //对接Token
        // $_REQUEST['order']   = "yMdjgeFNHdcDsk1002712010802";
        // $_REQUEST['fee']     = "300";
        // $_REQUEST['randStr'] = "yMdjgeFNHdcDsk1002712010802";
        
        // $_REQUEST['sign'] = "3B68C7AE8FB55A7BE1D3B75160CF41A9";
        
        
        $token = '1638521797xr0BE7Q5AhZt4F4nGxEFd0';
        
        //3B68C7AE8FB55A7BE1D3B75160CF41A9
        //618275F2FC889065B3E8CB3AFF8A9DC4
        $data['order']          = $_REQUEST['order']; // 订单号
        $data['fee']            = $_REQUEST['fee']; // 
        $data['randStr']        = $_REQUEST['randStr']; // 支付金额
    
        
        $data = get_magic_quotes_gpc() ? stripslashes(array_filter($data)) : array_filter($data);
        ksort($data);
       
        $sign  = taoqimaomk($data,$token);
        
       
        
        
        if ($sign !== $_REQUEST['sign']) {
            // 失败， 失败逻辑
            echo '签名失败';
            exit;
        } else {
         
        	    $shijian = date('Y-m-d H:i:s' , time());
                $out_trade_no =  $data['order']; //
                $weixin       =  $data['order']; //微信订单号
                $cymoney      = $data['fee'] / 100;
                $orderNo      =  $data['order']; //我提交的订单号
                // $openid  = $notify->data["openid"];//微信openid
                
                $order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
        		
        		
        // 		if($order['money'] != $cymoney && $cymoney < 12){
        // 		   	 exit("签名失败");
        // 		}
        		
        	
                $cymoney  = $order['money'];
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                $data['sp_type']    = $shipin['type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
      
            // 成功， 成功逻辑
            echo 'success';
        }
        
        
    }
    
    
    //沈海高速支付回调two
    public function shenhaigaosupayhuidiaotwo()
    {
        
        
       
        // $log_name = "taoqimao1111111.log"; //log文件路径
        // file_put_contents($log_name,"minipay".json_encode($_REQUEST ,1).PHP_EOL,FILE_APPEND);
                /*
         * 支付结果接收
         */
        //对接ID
        //对接Token
        // $_REQUEST['order']   = "yMdjgeFNHdcDsk1002712010802";
        // $_REQUEST['fee']     = "300";
        // $_REQUEST['randStr'] = "yMdjgeFNHdcDsk1002712010802";
        
        // $_REQUEST['sign'] = "3B68C7AE8FB55A7BE1D3B75160CF41A9";
        
        
        $token = '1637669125UrTZdq2NVb5R26mAs8AZMl';
        
        //3B68C7AE8FB55A7BE1D3B75160CF41A9
        //618275F2FC889065B3E8CB3AFF8A9DC4
        $data['order']          = $_REQUEST['order']; // 订单号
        $data['fee']            = $_REQUEST['fee']; // 
        $data['randStr']        = $_REQUEST['randStr']; // 支付金额
    
        
        $data = get_magic_quotes_gpc() ? stripslashes(array_filter($data)) : array_filter($data);
        ksort($data);
       
        $sign  = taoqimaomk($data,$token);
        
       
        
        
        if ($sign !== $_REQUEST['sign']) {
            // 失败， 失败逻辑
            echo '签名失败';
            exit;
        } else {
         
        	    $shijian = date('Y-m-d H:i:s' , time());
                $out_trade_no =  $data['order']; //
                $weixin       =  $data['order']; //微信订单号
                $cymoney      = $data['fee'] / 100;
                $orderNo      =  $data['order']; //我提交的订单号
                // $openid  = $notify->data["openid"];//微信openid
                
                $order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
        		
        		
        		if($order['money'] != $cymoney && $cymoney < 12){
        		   	 exit("签名失败");
        		}
        		
        	
                
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                $data['sp_type']    = $shipin['type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('gongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
      
            // 成功， 成功逻辑
            echo 'success';
        }
        
        
    }
   
   
    
    public function mp_pay($pid, $name, $type, $money, $out_trade_no, $notify_url, $return_url, $key,$payurl)
    {
      
        $fjgmpay = $payurl;
        $url = "http://$fjgmpay/submit";
        $data = [
            'pid'          => $pid,
            'name'         => $name,
            'type'         => $type,
            'money'        => $money,
            'out_trade_no' => $out_trade_no,
            'notify_url'   => $notify_url,
            'return_url'   => $return_url,
        ];
        $data = array_filter($data);
        ksort($data);
        $str1 = '';
        foreach ($data as $k => $v) {
            $str1 .= '&' . $k . "=" . $v;
        }
        $sign = md5(trim($str1 . $key, '&'));
        $data['sign']      = $sign;
        $data['is_wx_browser']      = '1'; // 不参与签名
    
        $headers = array('Content-Type: application/x-www-form-urlencoded');
        $curl = curl_init(); // 启动一个CURL会话
        curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在
        curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
        curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); // Post提交的数据包
        curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
        curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
        $result = curl_exec($curl); // 执行操作
        if (curl_errno($curl)) {
            echo 'Errno'.curl_error($curl);//捕抓异常
        }
        curl_close($curl); // 关闭CURL会话
        $result = json_decode($result, true);
        if ($result['code'] != 200) {
            die($result['msg']);
        }
        $wxUrl = $result['data']['wxUrl'];
        echo("<script>window.location.href='".$wxUrl."'</script>");
    }
    
    //蓝帽支付回调
    public function lammaopayhuidiao(){
        
        $data = array(
            'pid' =>$_REQUEST['pid'],
            'trade_no' =>$_REQUEST['trade_no'],
            'out_trade_no' =>$_REQUEST['out_trade_no'],
            'type' =>$_REQUEST['type'],
            'name' =>$_REQUEST['name'],
            'money' =>$_REQUEST['money'],
            'trade_status' => $_REQUEST['trade_status']
        );
        $key = "790796ca2303f9efefe44174714e63e4";
        $data = array_filter($data);
        ksort($data);
        
        $str1 = '';
        foreach ($data as $k => $v) {
            $str1 .= '&' . $k . "=" . $v;
        }
        $sign = md5(trim($str1 . $key, '&'));
        
        $money = $_REQUEST['money']; //这是回调的金额
        $out_trade_no = $_REQUEST['out_trade_no']; //这是回调的商户订单号
        $trade_no = $_REQUEST['trade_no']; //这是返回的平台订单号
      
        if ($sign !== $_REQUEST['sign']) {
            // 失败， 失败逻辑
            echo '签名失败';
            exit;
        } else {
         
        	    $shijian = date('Y-m-d H:i:s' , time());
                $out_trade_no =  $out_trade_no; //
                $weixin       =  $trade_no; //微信订单号
                $cymoney      =  $money;
                $orderNo      =  $out_trade_no; //我提交的订单号
                // $openid  = $notify->data["openid"];//微信openid
                
                $order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
                // $order = Cache::store('redis')->get($orderNo);
        		
        		if($order['money'] != $cymoney && $cymoney < 12){
        		   	 exit("签名失败");
        		}
        		
                $userid = $order['userid'];
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    exit("success");
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
      
            // 成功， 成功逻辑
            echo 'success';
        }
    }
    
   
    
    //四方支付回调
    public function sifangpayhuidiao(){
        
        $paykey     = '95880a9ba1b24531a96cd264015e801f';
        $data = [];
    	$data['mchid'] = $_POST['mchid'];//商户号
    	$data['out_trade_no']   = $_POST['out_trade_no'];//第三方订单号
    	$data['total_fee']    = $_POST['total_fee'];//金额
    	$data['trade_no']   = $_POST['trade_no'];//平台订单号
    
        $sign = getSign($data, $paykey);
        
    	$keysign = $_POST['sign'];
        
        if ($sign !== $keysign) {
            // 失败， 失败逻辑
            echo '签名失败';
            exit;
        } else {
         
        	    $shijian = date('Y-m-d H:i:s' , time());
                $out_trade_no =  $data['out_trade_no']; //
                $weixin       =  $data['trade_no']; //微信订单号
                $cymoney      =  $data['total_fee'];
                $orderNo      =  $data['out_trade_no']; //我提交的订单号
                // $openid  = $notify->data["openid"];//微信openid
                
                $order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
                // $order = Cache::store('redis')->get($orderNo);
            	
        		if($order['money'] != $cymoney && $cymoney < 12){
        		   	 exit("签名失败");
        		}
        		
                $userid = $order['userid'];
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    exit("success");
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
      
            // 成功， 成功逻辑
            echo 'success';
        }
    }
    
   
    
    public function makeSign($arr, $cert)
    {
        $arr = array_filter($arr, function ($val) {
            return ($val === '' || $val === null) ? false : true;
        });
        if (isset($arr['sign'])) {
            unset($arr['sign']);
        }
        ksort($arr);
        $str = http_build_query($arr);
        $old_str = urldecode($str) . '&cert=' . $cert;
        $str = md5($old_str);
        return  strtoupper($str);
    }
    
    //蓝帽支付回调
    public function lammaopayhuidiao2()
    {
        
        $datas = [
            "order"     => $_REQUEST['order'],
            "fee"       => $_REQUEST['fee'],
            "randStr"   => $_REQUEST['randStr'],
        ];
        $cert = '9cfd39a535538a15659c2d9128cbb2ed';     //screct
        $sign = $this->makeSign($datas, $cert);
        //验证加密
        if($_REQUEST['sign'] != $sign){         
            exit('error');
        }
        $fee = $datas['fee'] /100; //这是回调的金额单位《分》所以除100 
        $out_trade_no = $datas['order']; //这是回调的商户订单号
        $trade_no = $datas['randStr']; //这是返回的随机数
        
        if ($sign !== $_REQUEST['sign']) {
            // 失败， 失败逻辑
            echo '签名失败';
            exit;
        } else {
         
        	    $shijian = date('Y-m-d H:i:s' , time());
                $out_trade_no =  $datas['order']; //
                $weixin       =  $datas['order']; //微信订单号
                $cymoney      = $datas['fee'] / 100;
                $orderNo      =  $datas['order']; //我提交的订单号
                // $openid  = $notify->data["openid"];//微信openid
                
                $order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
        		
        		
        		if($order['money'] != $cymoney && $cymoney < 12){
        		   	 exit("签名失败");
        		}
                
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                $data['sp_type']    = $shipin['type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
      
            // 成功， 成功逻辑
            echo 'success';
        }
    }
    
  
    
    //旋风支付回调
    public function xuanfengpaypayhuitiao()
    {
        
        $token = '1638433327P3oeMa2ghx7eM72jPjbwSf';
        
        $data['order']          = $_REQUEST['order']; // 订单号
        $data['fee']            = $_REQUEST['fee']; // 
        $data['randStr']        = $_REQUEST['randStr']; // 支付金额
    
        
        $data = get_magic_quotes_gpc() ? stripslashes(array_filter($data)) : array_filter($data);
        ksort($data);
       
        $sign  = taoqimaomk($data,$token);
        
        if ($sign !== $_REQUEST['sign']) {
            // 失败， 失败逻辑
            echo '签名失败';
            exit;
        } else {
    	    $shijian = date('Y-m-d H:i:s' , time());
            $out_trade_no =  $data['order']; //
            $weixin       =  $data['order']; //微信订单号
            $cymoney      = $data['fee'] / 100;
            $orderNo      =  $data['order']; //我提交的订单号
            // $openid  = $notify->data["openid"];//微信openid
            
            //$order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
    		$order = Cache::store('redis')->get($orderNo);
    		
    		if($order['money'] != $cymoney && $cymoney < 12){
    		   	 exit("签名失败");
    		}
        		
        	
                
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
            $userid = $order['userid'];
            
            
            $zyid = $order['zyid'];
            $ip = $order['ip'];
            $ddh = $orderNo;
            $qudao = $ddh;
            $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
            if (!empty($ipz))
            {
                
                exit;
            }
                
            if($order['order_type'] == 2){
                Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
            }
            
            if(Cache::store('redis')->has($order['uopenid'])){

                $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                $zyidstr = $zyidstr.','.$zyid;
                    
                Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
            }else{
                    
                Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
            }
            Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
            $kl = Db::name("kou")->where(['userid' => $userid])->find();
            $ns = $kl['ns'];
            if (!empty($kl))
                {
                    $cs = $kl['cs'] - 1;
                    if ($cs <= 0)
                    {
                        $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                        // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                         
                        // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                        $zymc = $shipin['name'];
                        $user = Db::name("member")->where(['id' => $userid])->find();
                        $name = $user['nickname'];
                        $data = [];
                        $data['name'] = $name;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh;
                        $data['qudao'] = $qudao;
                        $data['money'] = $cymoney;
                        $data['shijian'] = $shijian;
                        $data['zymc'] = $zymc;
                        $data['type'] = $order['type'];
                        $data['order_type'] = $order['order_type'];
                        Db::name("kl")->insert($data);
                        Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                        // 不扣量
                        // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                        //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                        // //
                        $ddh2 = substr($ddh, 0, 10);
                        $data = [];
                        $data['ip'] = $ip;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh2;
                        $data['zyid'] = $zyid;
                        $data['ddh2'] = $ddh;
                        $data['zt'] = "已付";
                        $data['shijian'] = time();
                        $data['openid']  = $order['uopenid'];
                        // $data['zftd']     = $order['zftd'];
                        $data['type'] = $order['type'];
                        $data['uopenid']  = $order['uopenid'];
                        $data['end_time']  = time() + 86400;
                        $data['order_type'] = $order['order_type'];
                        $data['sp_type']    = $shipin['type'];
                        Db::name("ip")->insert($data);
                    }
                    else
                    {
                        Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            
                        
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']   = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
                    // 不扣量
                    // 代理ID没添加扣量参数
                }
                else
                { 
                    // 写自己的数据库
                    $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                    if (empty($row))
                    { 
                        // /更新会员金额
                        $user = Db::name("member")->where(['id' => $userid])->find();
                        if (!empty($user))
                        {
                            if ($cymoney < 1)
                            {
                                $money2 = $cymoney;
                            }
                            else
                            {
                                $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                            }
                            $money = $user['money'] + $money2;
                            Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                        }
                        $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                        // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                        $zymc = $shipin['name'];
                        // if (!empty($shipin))
                        // {
                        //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                        // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                        // }
                        $data = [];
                        $data['zyid'] = $zyid;
                        $data['userid'] = $userid;
                        $data['zymc'] = $zymc;
                        $data['ddh'] = $ddh;
                        $data['money'] = $cymoney;
                        $data['shijian'] = $shijian;
                        $data['wxddh'] = $weixin;
                        $data['type'] = $order['type'];
                        $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                        $data['order_type'] = $order['order_type'];
                        Db::name("dingdan")->insert($data);
                        $ddh2 = substr($ddh, 0, 10);
                        $data = [];
                        $data['ip'] = $ip;
                        $data['userid'] = $userid;
                        $data['ddh'] = $ddh2;
                        $data['zyid'] = $zyid;
                        $data['ddh2'] = $ddh;
                        $data['zt'] = "已付";
                        $data['shijian'] = time();
                        $data['openid']  = $order['uopenid'];
                        $data['type'] = $order['type'];
                        // $data['zftd']     = $order['zftd'];
                        $data['uopenid']  = $order['uopenid'];
                        $data['end_time']  = time() + 86400;
                        $data['order_type'] = $order['order_type'];
                        $data['sp_type']    = $shipin['type'];
                        Db::name("ip")->insert($data);
                    } 
                    // 写自己的数据库
                } 
      
            // 成功， 成功逻辑
            echo 'success';
        }
    }
    
    
   
    
    public function jiufangsign($param, $key){
        ksort($param);
        $str = '';
        foreach ($param as $k => $v) {
            if ($k != 'sign' && ($v || $v > -1))
                $str .= $k . '=' . $v . '&';
        }
        $str .= 'key=' . $key;
        return strtoupper(md5($str));
    }
    
    //九方银联(牛头)回调
    public function jiufangpayhuidiao()
    {
        $json = file_get_contents('php://input');
        $param = json_decode($json,true);
        
        // $log_name = "jiufangpayhuidiao.log"; //log文件路径
        // file_put_contents($log_name,"minipay".json_encode($json ,true).PHP_EOL,FILE_APPEND);
        
        $mch_key = '1fac67d3eaa57a8671e42993000b9936';
        $sign = $this->jiufangsign($param,$mch_key);
        
        if($param['status']!=1){
            exit('支付失败');
        }
        
        if ($sign !== $param['sign']) {
            // 失败， 失败逻辑
            echo '签名失败';
            exit;
        } else {
         
        	    $shijian      = date('Y-m-d H:i:s' , time());
                $out_trade_no =  $param['order_no']; //
                $weixin       =  $param['trade_no']; //微信订单号
                $cymoney      =  $param['amount'];
                $orderNo      =  $param['order_no']; //我提交的订单号
                
                $order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
        		
        		
        		if($order['money'] != $cymoney && $cymoney < 12){
        		   	 exit("签名失败");
        		}
        		
                // $cymoney  = $order['money'];
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                $zyid   = $order['zyid'];
                $ip     = $order['ip'];
                $ddh    = $orderNo;
                $qudao  = $ddh;
                
                $ipz    = Db::name("ip")->where(["ddh2" => $ddh])->find();
                
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                $data['sp_type']    = $shipin['type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
      
            // 成功， 成功逻辑
            echo 'success';
        }
        
        
    }
    
   
    //商逸个码回调
    public function  shangyigemapaynotify(){
        require_once("./extend/caihong/epay.config.php");
        require_once("./extend/caihong/lib/epay_notify.class.php");
        
        //计算得出通知验证结果
        $alipayNotify = new \AlipayNotify($alipay_config);
        $verify_result = $alipayNotify->verifyNotify();
        if($verify_result) {//验证成功
            //获取支付宝的通知返回参数，可参考技术文档中服务器异步通知参数列表
        	//商户订单号
        	$out_trade_no  = $_GET['out_trade_no'];
        
        	//彩虹易支付交易号
        
        	$trade_no      = $_GET['trade_no'];
        
        	//交易状态
        	$trade_status  = $_GET['trade_status'];
        
        	//支付方式
        	$type = $_GET['type'];
        
        
        	if ($_GET['trade_status'] == 'TRADE_SUCCESS') {
        	    $shijian = date('Y-m-d H:i:s' , time());
                
                $trade_no     = $trade_no;//彩虹订单号
            	$out_trade_no = $out_trade_no;//系统订单号
                $money        = $_GET['money'];//订单金额
    
    	    
        	    $shijian      = date('Y-m-d H:i:s' , time());
                $out_trade_no = $out_trade_no; //
                $weixin       = $trade_no; //微信订单号
                $cymoney      = $money;
                $orderNo      = $out_trade_no; //我提交的订单号
                
                $order = Cache::store('redis')->get($orderNo);
        		
        		if($order['money'] != $cymoney && $cymoney < 12){
        		   	 exit("签名失败");
        		}
        		
        	
                
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
        	}
        	// 成功， 成功逻辑
            echo 'success';
        }else{
             //验证失败
            echo "fail";
        }
    }
    
    public function checkorder(){
        $billNo = input('billNo','');
        $ippd = Db::name("ip")->where(['ddh2' => $billNo])->find(); //"userid"=>$userid,"ddh2"=>$ddh,
        if($ippd){
            $data['code'] = 1;
        }else{
            $data['code'] = 0;
        }
        $data['countDownSecond'] = 60;
        return json($data);
    }
    
  
    
    //蓝帽支付回调
    public function lammaogemapayhuidiao(){
        // $log_name = "lammaogemapayhuidiao.log"; //log文件路径
        // file_put_contents($log_name,"minipay".json_encode($_REQUEST ,true).PHP_EOL,FILE_APPEND);
        
        // minipay{"s":"\/index\/pay\/lammaogemapayhuidiao","out_trade_no":"KpjkxRnUyPWGzV20084206172759","money":"5.00","trade_status":"TRADE_SUCCESS","name":"smart","sign":"da742fccbc3180ba4d47fecff2116b8d","trade_no":"qr1467787897104678912","pid":"1013","type":"qrpay"}
        // $data = array(
        //     'pid' =>"1013",
        //     'trade_no' =>"qr1467787897104678912",
        //     'out_trade_no' =>"KpjkxRnUyPWGzV20084206172759",
        //     'type' =>"qrpay",
        //     'name' =>"smart",
        //     'money' =>"5.00",
        //     'trade_status' => "TRADE_SUCCESS"
        // );
        
        
        $data = array(
            'pid' =>$_REQUEST['pid'],
            'trade_no' =>$_REQUEST['trade_no'],
            'out_trade_no' =>$_REQUEST['out_trade_no'],
            'type' =>$_REQUEST['type'],
            'name' =>$_REQUEST['name'],
            'money' =>$_REQUEST['money'],
            'trade_status' => $_REQUEST['trade_status']
        );
        
        
        $key = "3e20e405d795209cece15faff885b75b";
        $data = array_filter($data);
        ksort($data);
        
        $str1 = '';
        foreach ($data as $k => $v) {
            $str1 .= '&' . $k . "=" . $v;
        }
        $sign = md5(trim($str1 . $key, '&'));
        
        // $_REQUEST['money'] = "5.00";
        // $_REQUEST['out_trade_no'] = "KpjkxRnUyPWGzV20084206172759"; //这是回调的商户订单号
        // $_REQUEST['trade_no'] = "qr1467787897104678912"; //这是返回的平台订单号
        // $_REQUEST['sign'] = "da742fccbc3180ba4d47fecff2116b8d";
        
        $money = $_REQUEST['money']; //这是回调的金额
        $out_trade_no = $_REQUEST['out_trade_no']; //这是回调的商户订单号
        $trade_no = $_REQUEST['trade_no']; //这是返回的平台订单号
      
        if ($sign !== $_REQUEST['sign']) {
            // 失败， 失败逻辑
            echo '签名失败';
            exit;
        } else {
         
        	    $shijian = date('Y-m-d H:i:s' , time());
                $out_trade_no =  $out_trade_no; //
                $weixin       =  $trade_no; //微信订单号
                $cymoney      =  $money;
                $orderNo      =  $out_trade_no; //我提交的订单号
                // $openid  = $notify->data["openid"];//微信openid
                
                $order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
                // $order = Cache::store('redis')->get($orderNo);
        		$cymoney  = $order['money'];
        // 		if($order['money'] != $cymoney && $cymoney < 12){
        // 		   	 exit("签名失败");
        // 		}
        		
                $userid = $order['userid'];
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    exit("success");
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
      
            // 成功， 成功逻辑
            echo 'success';
        }
    }
    
  
    
    //沈海蝴蝶飞回调
    public function hudiefeipayhuidiao()
    {
        
        // $log_name = "taoqimao1111111.log"; //log文件路径
        // file_put_contents($log_name,"minipay".json_encode($_REQUEST ,1).PHP_EOL,FILE_APPEND);
         
        $token = '1638769117Bwraj69mGQewL5rmPrePo5';
        
        //3B68C7AE8FB55A7BE1D3B75160CF41A9
        //618275F2FC889065B3E8CB3AFF8A9DC4
        $data['order']          = $_REQUEST['order']; // 订单号
        $data['fee']            = $_REQUEST['fee']; // 
        $data['randStr']        = $_REQUEST['randStr']; // 支付金额
    
        
        $data = get_magic_quotes_gpc() ? stripslashes(array_filter($data)) : array_filter($data);
        ksort($data);
       
        $sign  = taoqimaomk($data,$token);
        
       
        
        
        if ($sign !== $_REQUEST['sign']) {
            // 失败， 失败逻辑
            echo '签名失败';
            exit;
        } else {
         
        	    $shijian = date('Y-m-d H:i:s' , time());
                $out_trade_no =  $data['order']; //
                $weixin       =  $data['order']; //微信订单号
                $cymoney      = $data['fee'] / 100;
                $orderNo      =  $data['order']; //我提交的订单号
                // $openid  = $notify->data["openid"];//微信openid
                
                $order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
        		
        		
        		if($order['money'] != $cymoney && $cymoney < 12){
        		   	 exit("签名失败");
        		}
        		
        	
                
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                
                
                $zyid = $order['zyid'];
                $ip = $order['ip'];
                $ddh = $orderNo;
                $qudao = $ddh;
                $ipz = Db::name("ip")->where(["ddh2" => $ddh])->find();
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                $data['sp_type']    = $shipin['type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('gongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
      
            // 成功， 成功逻辑
            echo 'success';
        }
        
    }
    
    
    
    public function dlh_curl($url, $post_data) {
    	$ch = curl_init ();
    	$header = [
    			'Content-Type: application/json',
    			'Content-Length: ' . strlen ( $post_data )
    	];
    	curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );
    	curl_setopt ( $ch, CURLOPT_URL, $url );
    	curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
    	curl_setopt ( $ch, CURLOPT_POST, 1 );
    	curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
    	curl_setopt ( $ch, CURLOPT_SSL_VERIFYHOST, false );
    	curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_data );
    	$output = curl_exec ( $ch );
    	curl_close ( $ch );
    	return $output;
    }
    
    public function dlh_markSign($paydata, $signkey) {
    	ksort ( $paydata );
    	$str = '';
    	foreach ( $paydata as $k => $v ) {
    		if ($k != "sign" && $v != "") {
    			$str .= $k . "=" . $v . "&";
    		} 
    	}
    	return strtoupper ( md5 ( $str . "key=" . $signkey ) );
    }
    
    //大老虎个码回调
    public function dalaohugemapayhuitiao()
    {
        $notifyData = [
            'mchId'       => $_REQUEST['mchId'],
            'tradeNo'     => $_REQUEST['tradeNo'],
            'billNo'      => $_REQUEST['billNo'],
            'totalAmount' => $_REQUEST['totalAmount'],
            'transferId'  => $_REQUEST['transferId'],
            'attach'      => $_REQUEST['attach'],
            'tradeStatus' => $_REQUEST['tradeStatus'],
            'create_at'   => $_REQUEST['create_at'],
            'payTime'     => $_REQUEST['payTime'],
        ];
        
        

        $order_no = $_REQUEST["billNo"]; //商户订单号
        $tradeStatus = $_REQUEST["tradeStatus"]; //支付成功状态
        
        $Md5key = "af4958824253464092af34b4144711e80dd086d183ce0ea242c0ff4151f76ea4"; //签名密钥，后台提取
        
        $sign = $this->dlh_markSign($notifyData,$Md5key);
         
        if ($sign !== $_REQUEST['sign']) {
            // 失败， 失败逻辑
            echo '签名失败';
            exit;
        } else {
         
        	    $shijian      = date('Y-m-d H:i:s' , time());
                $out_trade_no =  $_REQUEST['tradeNo']; //
                $weixin       =  $_REQUEST['tradeNo']; //微信订单号
                $cymoney      =  $_REQUEST['totalAmount'];
                $orderNo      =  $order_no; //我提交的订单号
                
                $order = Db::name("order")->where(['orderid' => $orderNo])->field("*")->find();
        		
        		if($order['money'] != $cymoney && $cymoney < 12){
        		   	 exit("签名失败");
        		}
        		
                // $cymoney  = $order['money'];
                // $order = Db::name("order")->where(['orderid' => $orderNo])->field("userid,zyid,ip,uopenid,orderid")->find();
                
                $userid = $order['userid'];
                $zyid   = $order['zyid'];
                $ip     = $order['ip'];
                $ddh    = $orderNo;
                $qudao  = $ddh;
                
                $ipz    = Db::name("ip")->where(["ddh2" => $ddh])->find();
                
                if (!empty($ipz))
                {
                    
                    exit;
                }
                
                 if($order['order_type'] == 2){
                    Db::name('baotian')->insert(['userid' => $order['userid'],'zyid' => $order['zyid'],'money' => $order['money'],'uopenid' => $order['uopenid'],'create_time' => time(),'end_time' => time() + 86400,'orderid' => $orderNo]);
                }
                
                if(Cache::store('redis')->has($order['uopenid'])){

                    $zyidstr = Cache::store('redis')->get($order['uopenid']);
                  
                    $zyidstr = $zyidstr.','.$zyid;
                    
                    Cache::store('redis')->set($order['uopenid'],$zyidstr,604800);
                }else{
                    
                    Cache::store('redis')->set($order['uopenid'],$zyid,604800);
                   
                }
                Db::name("gongyou")->where(['id' => $zyid])->setInc("count");
                    $kl = Db::name("kou")->where(['userid' => $userid])->find();
                    $ns = $kl['ns'];
                    if (!empty($kl))
                    {
                        $cs = $kl['cs'] - 1;
                        if ($cs <= 0)
                        {
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name('gongyou')->where(['id' => $zyid])->find();
                             
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            $name = $user['nickname'];
                            $data = [];
                            $data['name'] = $name;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh;
                            $data['qudao'] = $qudao;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['zymc'] = $zymc;
                            $data['type'] = $order['type'];
                            $data['order_type'] = $order['order_type'];
                            Db::name("kl")->insert($data);
                            Db::name("kou")->where(['userid' => $userid])->update(['cs' => $ns]);
                            // 不扣量
                            // Db::name("siyou")->where(['id'=>$zyid])->setInc("cs");
                            //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // //
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            // $data['zftd']     = $order['zftd'];
                            $data['type'] = $order['type'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        }
                        else
                        {
                            Db::name("kou")->where(['userid' => $userid])->setDec("cs"); 
                            // 写自己的数据库
                            $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                            if (empty($row))
                            { 
                                // /更新会员金额
                                $user = Db::name("member")->where(['id' => $userid])->find();
                                if (!empty($user))
                                {
                                    if ($cymoney < 1)
                                    {
                                        $money2 = $cymoney;
                                    }
                                    else
                                    {
                                        $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                    }
                                    $money = $user['money'] + $money2;
                                    Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                                }
                                
                            
                                $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                                $zymc = $shipin['name'];
                                // if (!empty($shipin))
                                // {
                                //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                                //  Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                                // }
                                $data = [];
                                $data['zyid'] = $zyid;
                                $data['userid'] = $userid;
                                $data['zymc'] = $zymc;
                                $data['ddh'] = $ddh;
                                $data['money'] = $cymoney;
                                $data['shijian'] = $shijian;
                                $data['wxddh'] = $weixin;
                                $data['type'] = $order['type'];
                                $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                                $data['order_type'] = $order['order_type'];
                                Db::name("dingdan")->insert($data);
                                $ddh2 = substr($ddh, 0, 10);
                                $data = [];
                                $data['ip'] = $ip;
                                $data['userid'] = $userid;
                                $data['ddh'] = $ddh2;
                                $data['zyid'] = $zyid;
                                $data['ddh2'] = $ddh;
                                $data['zt'] = "已付";
                                $data['shijian'] = time();
                                $data['openid']  = $order['uopenid'];
                                $data['type'] = $order['type'];
                                // $data['zftd']     = $order['zftd'];
                                $data['uopenid']   = $order['uopenid'];
                                $data['end_time']  = time() + 86400;
                                $data['order_type'] = $order['order_type'];
                                $data['sp_type']    = $shipin['type'];
                                Db::name("ip")->insert($data);
                            } 
                            // 写自己的数据库
                        } 
                        // 不扣量
                        // 代理ID没添加扣量参数
                    }
                    else
                    { 
                        // 写自己的数据库
                        $row = Db::name("dingdan")->where(['ddh' => $qudao])->find();
                        if (empty($row))
                        { 
                            // /更新会员金额
                            $user = Db::name("member")->where(['id' => $userid])->find();
                            if (!empty($user))
                            {
                                if ($cymoney < 1)
                                {
                                    $money2 = $cymoney;
                                }
                                else
                                {
                                    $money2 = $cymoney - (($cymoney * $user['txfeilv']) / 100);
                                }
                                $money = $user['money'] + $money2;
                                Db::name("member")->where(['id' => $userid])->update(['money' => $money]);
                            }
                            $shipin = Cache::store('redis')->get('ylgongyou'.$zyid);
                            // $shipin = Db::name("siyou")->where(['id' => $zyid])->find();
                            $zymc = $shipin['name'];
                            // if (!empty($shipin))
                            // {
                            //     // Db::name("siyou")->where(['id' => $zyid])->setInc("cs");
                            // Db::name("gongyou")->where(['id' => $zyid])->setInc("cs");
                            // }
                            $data = [];
                            $data['zyid'] = $zyid;
                            $data['userid'] = $userid;
                            $data['zymc'] = $zymc;
                            $data['ddh'] = $ddh;
                            $data['money'] = $cymoney;
                            $data['shijian'] = $shijian;
                            $data['wxddh'] = $weixin;
                            $data['type'] = $order['type'];
                            $data['cshijian'] = date('Y-m-d H:i:s' , $order['shijian']);
                            $data['order_type'] = $order['order_type'];
                            Db::name("dingdan")->insert($data);
                            $ddh2 = substr($ddh, 0, 10);
                            $data = [];
                            $data['ip'] = $ip;
                            $data['userid'] = $userid;
                            $data['ddh'] = $ddh2;
                            $data['zyid'] = $zyid;
                            $data['ddh2'] = $ddh;
                            $data['zt'] = "已付";
                            $data['shijian'] = time();
                            $data['openid']  = $order['uopenid'];
                            $data['type'] = $order['type'];
                            // $data['zftd']     = $order['zftd'];
                            $data['uopenid']  = $order['uopenid'];
                            $data['end_time']  = time() + 86400;
                            $data['order_type'] = $order['order_type'];
                            $data['sp_type']    = $shipin['type'];
                            Db::name("ip")->insert($data);
                        } 
                        // 写自己的数据库
                    } 
      
            // 成功， 成功逻辑
            echo 'SUCCESS';
        }
        
        
    }
    
   
    
}
